CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Aug 2013
    Posts
    2

    running excel makro outside excel pt.2

    Hello.

    As part of my internship I am writing a makro. Ultimatly I want to start it with an batch file. To keep stuff simple I tried to start a small makro with dynamic parameters just like in an old thread (http://forums.codeguru.com/showthrea...-outside-excel).

    For testing purpose everything resides in the same folder under c:\script\

    The excel file with the makro is called: main.xlsm

    makro code:
    Code:
    Sub Proc(sParam1 As String, iParam2 As Integer)
    	MsgBox sParam1 & " is " & iParam2 & " Years Old"
    End Sub
    batch file:
    Code:
    @echo off 
    cscript c:\script\test.vbs
    pause
    vbs file:
    Code:
    Option Explicit
    
    Private Sub SimpleCall()
    	Dim oExcelApp As Object
    
    	set oExcelApp = oExcelApp.Workbooks.Open("C:\script\main.xlsm") 
    	oExcelApp.Visible = True
    	oExcelApp.run "Modul2.proc", "David", "30"
    End Sub

    Thank you very much in advance!!

    cheers

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: running excel makro outside excel pt.2

    Is there a particular problem you're having?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2013
    Posts
    2

    Re: running excel makro outside excel pt.2

    Quote Originally Posted by dglienna View Post
    Is there a particular problem you're having?
    when running the batch file it says:
    c:\script\test.vbs(4, 16) Kompilierungsfehler in Microsoft VBScript: Anweisungsende erwartet
    Translated it would be something like: "Compiling error in test.vbs(4,16): end of command/expression expected"

    So row 4 would be referring to this command: Dim oExcelApp As Object
    What is wrong here? When I delete this row the error does not occur but also nothing else works.

    Any ideas how to get this working?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: running excel makro outside excel pt.2

    which line does it STOP at (HIGHLIGHTED YELLOW IN USA)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: running excel makro outside excel pt.2

    I would say it is this line
    Code:
    set oExcelApp = oExcelApp.Workbooks.Open("C:\script\main.xlsm")
    I think you need to use a CreateObject() call there.

    Mind you that I do very little scripting and do not do much with Excel at all.

    Sample from here http://support.microsoft.com/kb/245115
    Code:
    ' No reference to a type library is needed to use late binding.
    ' As long as the object supports IDispatch, the method can 
    ' be dynamically located and invoked at run-time.
    
    ' Declare the object as a late-bound object
      Dim oExcel As Object
    
      Set oExcel = CreateObject("Excel.Application")
    
    ' The Visible property is called via IDispatch
      oExcel.Visible = True
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured