-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.

8
  • Are all macros disabled like the error message says? Commented Jan 18, 2023 at 5:17
  • @braX, i have enabled all the macros settings in excel. Shouldn't be the setting problems, i think there is something wrong in my VBScript Commented Jan 18, 2023 at 5:31
  • 1
    Please do not post your code as images. No one can copy/paste it then. Commented Jan 18, 2023 at 5:34
  • 1
    If you want a macro to be available to any workbook, then put it in the personal workbook. Commented Jan 18, 2023 at 6:20
  • 1
    Try objExcelApp.Run "'" & iWb.Name & "'!Sheet3.contract_vba" Commented Jan 18, 2023 at 7:02

1 Answer 1

1

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

 objExcelApp.Run "'" & iWb.Name & "'!Sheet3.contract_vba"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.