Run-time error '1004': Cannot run macro VBA

NuMbErSNeVeRLie

New Member
Joined
Aug 7, 2018
Messages
2
I am having trouble running a macro that is in another WB. This worked previously, but now doesn't seem to work... Please help!


Sub RunTestTemplate()
'Establish Variables
Dim RMPath As String
Dim TestFile As String
Dim CorpGrpNum As String
Dim Macro1 As String
Dim Macro2 As String
Dim Macro3 As String
Dim x As Integer
Dim SavePath As String
Dim FileNameLen As Long
Dim CallPath As String
Dim fso As Object
Dim Revenue As Worksheet
Dim Manual As Worksheet
Dim Experience As Worksheet
Dim Ratebook As Worksheet


Set fso = CreateObject("Scripting.FileSystemObject")


'Open and Run Rating Model

'Define Some Variables
TestFile = ActiveWindow.Caption
RMPath = Worksheets("Revenue Calculation").Range("G2").Value
CorpGrpNum = Worksheets("Revenue Calculation").Range("B14").Value
Set Revenue = Worksheets("Revenue Calculation")
Set Manual = Worksheets("2016 - 2020 Manual RAF")
Set Experience = Worksheets("2017 - 2020 Experience RAF")
Set Ratebook = Worksheets("Ratebook v3 by county")

Workbooks.Open Filename:=RMPath, ReadOnly:=False


If Revenue.Range("B6").Value = "Renewal" Then
Worksheets("BlockSummary").Visible = True
Worksheets("BlockSummary").Range("C2").Value = "On"
End If
Worksheets("RenewalInputScreen").Range("B5").Value = Revenue.Range("B14").Value


Macro1 = "!RenewalGroupInfo"
Macro2 = "!RenewalBuild"
Macro3 = "!RunPricing"

Application.Run "'" & RMPath & "'" & Macro1
Application.Run "'" & RMPath & "'" & Macro2


RMPath is the filepath... All names and filepaths have been checked and rechecked.

Thanks!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
In future, please use code tags when posting code
- click on # icon above post window and paste inside the code tags
- using code tags formats it etc which makes it easier to read

Replace
Code:
Application.Run "'" & RMPath & "'" & Macro1
Application.Run "'" & RMPath & "'" & Macro2

with
Code:
Dim s1 As String, s2 As String
s1 = "'" & RMPath & "'" & Macro1
s2 = "'" & RMPath & "'" & Macro2
Debug.Print "s1", s1
Debug.Print "s2", s2
Application.Run s1
Application.Run s2

Look in the immediate window (view with {Ctrl} G ) to see if the strings s1 & s2 are correct

Is the other workbook open when macro is run?
 
Last edited:
Upvote 0
Mapping problem??? Try this:

Are both workbooks on a local drive?
- if not, put a copy of both workbooks there, amend all paths required to run them locally and run...

If it fails to rum locally, then there is a problem in the code
 
Last edited:
Upvote 0
Is the code you posted, the complete code, or have you left parts out?
If it's the complete code, step through the code using F8. What happens when you get to the first Application.run line?
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,806
Members
449,337
Latest member
BBV123

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