0

Trying to run excel macro using command prompt through VBS. Excel file open ups but not able to run macro. The name of Macro as well as module is "Wallet"

While tryig to view macro, it reflects as "PERSONAL.XLSB!WALLET"

Pls help

Sub ExcelMacroExample()

Dim xlApp
Dim xlBook

Set xlApp = CreateObject("excel.application")
Set xlBook = xlApp.Workbooks.Open("C:\Output\abc.xlsb")
xlApp.Visible = True
xlApp.Run "Wallet"
xlApp.Save
xlApp.ActiveWorkbook.Close
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing

End Sub
3
  • Try changing line xlApp.Run "Wallet" to xlApp.Run "PERSONAL.XLSB!WALLET" and then running the code. Commented May 10, 2020 at 12:50
  • @shrivallabha.redij nope!....its not working Commented May 10, 2020 at 13:22
  • I just realized that my personal.xlsb is not available in the excel i am trying to run macro. Is there any way I can make this available....? Commented May 10, 2020 at 14:08

1 Answer 1

2

Change your code like that

Sub ExcelMacroExample()

    Dim xlApp
    Dim xlBook

    Set xlApp = CreateObject("excel.application")
    Set xlBook = xlApp.Workbooks.Open("C:\Output\abc.xlsb")
    xlApp.Visible = True
    xlApp.Workbooks.Open ("Path to your Personal.XLSB")
    xlApp.Run "Personal.XLSB!Macro"

    'xlApp.Save                   <= This line would not work, xlApp does not have a Save Method
    'xlApp.ActiveWorkbook.Close   <= You already have the reference to the workbook. It is xlBook
    xlBook.Close True           ' <= This will save and close the workbook you opened
    xlApp.Quit

    Set xlBook = Nothing
    Set xlApp = Nothing

End Sub

If you do not know where your Personal.xlsb is try the standard location.

xlApp.Workbooks.Open (xlApp.StartupPath & xlApp.PathSeparator & "Personal.XLSB")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.