-
Feb 19th, 2013, 04:47 AM
#1
Thread Starter
New Member
Calling macro from VB script
Hi I am trying to call a macro in test.xls using the following VB script
Option Explicit
Dim returnVal
returnVal = 0
WScript.Echo returnVal
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("D:\test.xls", 0, True)
xlApp.Run "macro1"
xlBook.Close false
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
WScript.Echo returnVal
''WScript.Quit returnVal
The macro defined in test.xls is :
Dim returnVal as Boolean
sub macro1()
returnVal = 1
Exit Sub
...
End Sub
When I try to run the VB script I get a pop up window with value 0 (that is for the echo I am doing at the start). Then I get a pop up window with value 0 again. Looks like the value from the macro is not being returned.
Where am I going wrong here.
-
Feb 19th, 2013, 09:42 AM
#2
Re: Calling macro from VB script
Moved to the VBScript forum.
-
Feb 19th, 2013, 10:02 AM
#3
Re: Calling macro from VB script
Looks like you defined it twice:
Dim returnVal
Dim returnVal as Boolean
-tg
Tags for this Thread
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
|