I would like to share some Excel macro with some collegues who dont know how to use it well.
I've never done anything in VBS but I've find the following .vbs to launch the macro :
Option Explicit
Dim xlApp, xlBook, oFSO, oShell, oExcel, oFile, oSheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("C:\Users\Desktop\API.xlsm")
xlApp.Run "getIEX"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
WScript.Echo "End"
WScript.Quit
At some point of my Excel's macro I have a Userform on which I have a screen of a part of my Excel Table's sheet. On this userform I have 2 button : Auto-Save or Save Manualy.
if I press auto-save all is fine cause my Excel's macro keep going, save the file and then the vbs script close the unvisible excel workbook.
But, if they press save manualy (which end the Excel's macro), same thing happen... So I tried to call 2 others script from Excel VBA with this code :
If ResponseX = vbYes Then
Call savefile
Shell "wscript.exe ""C:\Users\Desktop\UserFormYes.vbs"""
Else
Shell "wscript.exe ""C:\Users\Desktop\UserFormNo.vbs"""
Exit Sub
One if they press Auto-Save (to end the script) and another one for the manualy save which will make xlApp visible before quit the WScript.
The problem is : My object (xlApp) is not share between .vbs scripts.
The first .vbs script create the object xlApp and launch the VBA macro. Then the macro launch another .vbs script I would like to do 2 .vbs scripts : .First one if they press Yes :
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
WScript.Echo "End"
WScript.Quit
.Second one if they press no :
Set xlApp.Visible = True
WScript.Quit
How can I do this ? Is it possible ? Because currently, I have the error : Object Require : xlApp
Thanks :)