rob
rob

Reputation: 317

Running Sub in Another Excel Workbook with Variable File Name

I currently run a sub in another (open) workbook using this line:

Application.Run ("'NDS Analytics.xlsm'!Process")

The names of the referenced workbooks are changing so I would like to change the reference so that instead of looking for file NDS Analytics.xlsm it looks for an open file that contains the words "NDS Analytics".

There will only ever be one file with this name open at a time and it could be called either NDS Analytics.xlsm, wNDS Analytics.xlsm or 40ghNDS Analytics.xlsm.

Upvotes: 0

Views: 124

Answers (1)

VBasic2008
VBasic2008

Reputation: 55073

Application Run with Variable Workbook

Option Explicit

Sub runProcess()
    Dim wb As Workbook
    For Each wb In Workbooks
        If UCase(wb.Name) Like UCase("*NDS Analytics*.xlsm") Then
            Application.Run "'" & wb.Name & "'!Process"
            Exit For
        End If
    Next wb
End Sub

Upvotes: 2

Related Questions