-2

I wanted to run macros using the command prompt, the macros are placed under a sheet in excel. I created a VBScript and let it automatically run in command prompts, but it shows "The macro may not be available in this workbook or all macros may be disabled."

This is my VBA code

enter image description here

This is my VBS

'Create Excel App Instance & Open Xlsm File
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = True
objExcelApp.DisplayAlerts = False

'Define Macro File & Path
sFilePathXlsm = "C:\Users\roeyj\OneDrive\Desktop\Intern\Monthly PM\Service Contracts as of 2022 (macro).xlsm"
Set iWb = objExcelApp.Workbooks.Open(sFilePathXlsm)

'1. Run 1st Macro in another Excel
sMacroToRun = "'" & sFilePathXlsm & "'!Sheet3.contract_vba"
objExcelApp.Run sMacroToRun


'Save & Close file
iWb.Save
iWb.Close
objExcelApp.DisplayAlerts = True
objExcelApp.Quit

This is what the command prompt shows

enter image description here

The excel file is opened but the macros don't run, I need help with this.

1 Answers1

1

Run doesn't want the full path, so try:

 objExcelApp.Run "'" & iWb.Name & "'!Sheet3.contract_vba"
Tim Williams
  • 154,628
  • 8
  • 97
  • 125