Application.Run returning error "400"

paun_shotts

New Member
Joined
Nov 4, 2021
Messages
38
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I have code in workbook A in a macro.
I have a button in WorkBook A that when pressed runs the below code.
I want to open another workbook, and then run the macro that is in workbookA on the workbook that was just opened.
VBA Code:
Sub RunMacro()
Workbooks.Open "C:\Users\spotts\Documents\Excel VBA\po ang1324-converted.xls"
Application.Run "po ang1324-converted.xls!ApplyFormatting"
End Sub

The workbook "po ang1324-converted.xls" opens fine, then I get error message "400" and the macro does not run.
I believe the code is all correct, but I keep getting this error. If I comment out the line starting with "Application.Run" then I do not get the error message.
Can someone please help??

400.JPG
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
There is a lot to unpack here. Need to know which Workbook is already open, the Path of the Workbook that you want to open, and the location of the Macro that you want to run.
 
Upvote 0
There is a lot to unpack here. Need to know which Workbook is already open, the Path of the Workbook that you want to open, and the location of the Macro that you want to run.
Hi SkyBot, thanks for your response.
The Workbook that is open is: C:\Users\spotts\Documents\Excel VBA\po ang1323-converted.xlsm
The path of the workbook that I want to open is: "C:\Users\spotts\Documents\Excel VBA\po ang1324-converted.xls"

The Macro is in the workbook "po ang1323-converted.xlsm"
In this workbook, I have a button on Sheet 1, the button it linked to the code in the above post "Sub RunMacro()"
This code is opening "C:\Users\spotts\Documents\Excel VBA\po ang1324-converted.xls" with no issues.
But when it gets to the 2nd line, "Application.Run...." I get the error 400. If this line is commented out, that no error message, but obviously I dont want to comment it out, becasue I want to run the Macro in the newly opened workbook.

The start of the Macro that I want to run looks like this:
VBA Code:
Sub ApplyFormatting()

Dim iRange As Range
Dim iCells As Range
Dim lastRow As Long

etc
etc
etc
 
Upvote 0
Thank you for your response. Is it possible for you to show me the VBA project location of your Macro. I have submitted an image of what you VBA Project model may look like.
1691457890125.png
 
Upvote 0
More specifically, is the Macro in the Workbook, or a Module, or a Worksheet? If in a Module, have you named the Module?
 
Upvote 0
More specifically, is the Macro in the Workbook, or a Module, or a Worksheet? If in a Module, have you named the Module?
The macro I want to run is in a Module, I've named the Module "ApplyFormatting"
In Sheet1, I have the code:
VBA Code:
Sub RunMacro()
Workbooks.Open "C:\Users\spotts\Documents\Excel VBA\po ang1324-converted.xls"
Application.Run "po ang1324-converted.xls!ApplyFormatting"
End Sub
This is linked to a button on Sheet 1, when I press the button on Sheet1 I get the "400" error message
When I just press "play" on the code in Sheet1, I get error message "1004 - Application-defined or object-defined error"
In both scenarios, the correct Workbook is opening, but the Macro is not running.
 
Upvote 0
I have run the macro by itself and it works perfectly with no issues.
I have run the below code by itself and the workbook opens with no issues:
Code:
Workbooks.Open "C:\Users\spotts\Documents\Excel VBA\po ang1324-converted.xls"

The issue is caused in this line of code:
VBA Code:
Application.Run "po ang1324-converted.xls!ApplyFormatting"

There must be some error in the way that I am referencing the macro in the above line.
Ive spent hours researching online and from what I can find, this is how you do what I need to do, but for some reason its not working for me and im now clueless.
 
Upvote 0
SOLVED - I found another way of doing what I needed without using Application.Run
 
Upvote 0
Good to hear you found a solution.
If you would like to post the solution then it is perfectly fine to mark that post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
Note that the tick checkmark is not a 'Solved' button in our forums.
 
Upvote 1

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

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