TTT
TTT

Reputation: 4434

Calling a macro from another workbook not always being executed

In Excel Workbook A, I have a macro which

  1. fills inputs for a series of other workbooks
  2. calls the AUTORUN
  3. collects results in a summary tab

The logic is quite simple but I found that Step 2 is not always being executed, which is quite strange... I have confirmed that inputs have been properly entered and I can go each failed Excel workbook and run the simulation by clicking the button linked to AUTORUN. Does anyone have any suggestions on this (I am using EXCEL 2013)? Thanks in advance! Below is how macro from a different workbook is called.

        Workbooks(NewFileName).Activate
        Application.Run ("'" & NewFileName & "'!AUTORUN")

Upvotes: 0

Views: 59

Answers (1)

Maxime Porté
Maxime Porté

Reputation: 1074

I run some tests

File 1 (the caller):

The method AAATEST() is in a Module

Public Sub AAATEST()
    Dim file As String: file = "test.xlsm"
    call Workbooks.Open("C:\temp\" & file)

    Workbooks(file).Activate
    Call Application.Run("'" & file & "'!AUTORUN")
End Sub

File 2 (with autorun):

The method AUTORUN() is in a Module

Public Sub AUTORUN()
    MsgBox "autorun is my life"
End Sub

Result:

I always receive the message when running the AAATEST() method. I suspect a not raised error in the AUTORUN.

To check if the Autorun is run or not, add Stop as first instruction in your Method and execute your code step by step (with F8)

Public Sub AUTORUN()
    Stop
    ...
    MsgBox "autorun is my life"
End Sub

Upvotes: 1

Related Questions