Run macro from another workbook

Octonet

New Member
Joined
Sep 5, 2020
Messages
27
Office Version
  1. 2019
Platform
  1. Windows
I have workbook A open. In A I have a macro that has to call a macro (New_week) in workbook B.
Problem is that I have only variables as name for B.
Here is the script of the macro in book A.
Sub Downtime_ASL()
'
' Downtime_ASL Macro
'
Dim Mypath As String
Dim Myfile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim GL As Date
Mypath = "I:\Excel\VBA project downtime\ASL"
If Right(Mypath, 1) <> "\" Then Mypath = Mypath & "\"
Myfile = Dir(Mypath & "Downtime*.xlsm", vbNormal)
If Len(Myfile) = 0 Then
MsgBox "Nothing found...", vbExclamation
Exit Sub
End If
Do While Len(Myfile) > 0
GL = FileDateTime(Mypath & Myfile)
If GL > LatestDate Then
LatestFile = Myfile
LatestDate = GL
End If
Myfile = Dir
Loop
Workbooks.Open Mypath & LatestFile
Application.Run "'Mypath & LatestFile'!New_week"
End Sub

In the directory where B is located there are a lot of files. This macro looks for the last saved file and opens it.
In workbook B there is a macro "New_week" that I want to call.
The workbook will be opened, so the variables are known.
But I get errors when I get to the line Application.Run "'Mypath & LatestFile'!New_week".
The error says "In c:\users\documents\ there is nof file "Mypath & LatestFile.xls"

What did I do wrong ?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,214,426
Messages
6,119,411
Members
448,894
Latest member
spenstar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top