-
August 6th, 2013, 09:26 AM
#1
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
-
August 6th, 2013, 12:04 PM
#2
Re: running excel makro outside excel pt.2
Is there a particular problem you're having?
-
August 7th, 2013, 02:43 AM
#3
Re: running excel makro outside excel pt.2
Originally Posted by dglienna
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?
-
August 8th, 2013, 02:46 AM
#4
Re: running excel makro outside excel pt.2
which line does it STOP at (HIGHLIGHTED YELLOW IN USA)
-
August 9th, 2013, 02:16 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|