Reputation: 35577
We have a macro that takes approximately 20 minutes to complete. We've got a c# winform that our user has access to - it contains a "Run Macro" button. I'd like it so that the user can hit the button and then actually close the form and then in 20mins time see the output from the macro in a pre-defined directory.
Is it simply a case of creating a delegate and letting the delegate run the macro or is the above not a trivial matter?
Couple of ideas which might be viable:
Upvotes: 3
Views: 2301
Reputation: 149315
Yes it is simple.
Use C# to launch a VBS File. The code will be something like
System.Diagnostics.Process.Start(@"cscript //B //Nologo c:\MyScript.vbs");
The above code will launch the VBScript with no prompts or errors and no shell logo.
Next Step is to create a vbs file.
Open Notepad and paste this code and save it as a MyScript.vbs
file
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
'~~> Change Path here
Set xlBook = xlApp.Workbooks.Open("C:\Test.xls", 0, True)
xlApp.Run "TestMacro"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
Upvotes: 3