PDA

View Full Version : Running macro on another workbook



aryank2000
04-21-2016, 09:54 AM
I wrote a macro which deletes blank rows and saves the file into a csv file. The name of the xls file which has macro is MacroFile.xls. I want to run this macro on an excel file (Sourcefile.xls). So when I open the macrofile.xls, the macro should run on Sourcefile.xls. I tried using Application.Run("SourceFile.XLS!MyMacroName") in Macrofile.xls. I get error. Any help would be appreciated. Here is what i have in sourcefile.xls.

sub promacro()
' code here
end sub

Sub runmacro()


Application.Run ("C:\folder\Macrofile.XLS!promacro")


End Sub

Can someone suggest what am i missing?

Bob Phillips
04-22-2016, 06:19 AM
You don't need brackets, just


Application.Run "C:\folder\Macrofile.XLS!promacro"

aryank2000
04-22-2016, 06:46 AM
thank you. tried, but it doesnt work either. i get the following error

run-time error '1--4': application-defined or object-defined error.



You don't need brackets, just


Application.Run "C:\folder\Macrofile.XLS!promacro"

Bob Phillips
04-22-2016, 08:54 AM
Couple of points I should have noticed earlier.

You cannot have macros in a .xlsx file, it must be .xlsm or .xlsb.

You cannot run a macro from a folder, you have to open it and then run it.