How do I save a macro as vbs?
I don't know why I can't name my macrocode from R, This is my code I'm trying to save as a vbs file: (should I save it in Notepad app?)
Sub vb()
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("path.xlsm", 0, False)
xlApp.Visible = True
xlApp.Run "Countries"
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
How do I save the above code as vbs?
+3
source to share
2 answers
Use the below VBS code as you cannot save VBA code as VBS as schema or say they are not on the same page as C and C ++, it is the same.
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("path.xlsm")
objExcel.Application.Visible = True
objExcel.Application.Run "path.xlsm!Countries" 'Refer to the below if the code is under sheet
objExcel.ActiveWorkbook.Close
WScript.Echo "Finished."
WScript.Quit
If you placed the code on the sheet. user of this line
objExcel.Application.Run "path.xlsm!sheet1.dog"
Hope this will resolve your request. Happy coding.
0
source to share