I'm using this script from the forum to run a macro in excel.
//Put this VBScript block at top of script
VBSTART
Sub OpenAndRun(xlFileName, MacroName)
Set xlApp = CreateObject("Excel.Application")
'remove next line to make Excel invisible
xlApp.visible = true
Set xlBook = xlApp.WorkBooks.Open(xlFileName)
xlApp.Run(MacroName)
'Uncomment next line to quit Excel
'xlApp.quit
End Sub
VBEND
//Use this line when you want to run the Excel macro:
VBRun>OpenAndRun,c:\files\myexcel.xls,MyMacro
How can I get a return variable back ?
Is the any way to run the macro as I am in the code above from within a function.
The function then takes a value that is placed on the worksheet by the excel macro, which then allows me to use VBEval ?
Is that possible ?
Or do I need to do a seperate DDE request ?
If so is there anyway to do that with excel hidden like in the above code ?
help with vb script
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You mean get a variable back from Excel?
The function call can't do that. Probably best way would be to have Excel put the value in a cell and then use a simple DDE call or VBscript to read the cell.
That code is just an example that creates an instance of Exce, opens an xls file and then runs the macro. You could rearrange that code however you like, and have the bit that runs the macro wherever you want.
The function call can't do that. Probably best way would be to have Excel put the value in a cell and then use a simple DDE call or VBscript to read the cell.
That code is just an example that creates an instance of Exce, opens an xls file and then runs the macro. You could rearrange that code however you like, and have the bit that runs the macro wherever you want.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 50
- Joined: Thu Feb 21, 2008 9:11 pm
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
I would use VBScript to read the cell before the close. See link I posted earlier on how to read Excel data. That article has VBscript for reading data from Excel. There's also a sample script that comes with Macro Scheduler with same code. Insert code that reads the data between the run and the close.