• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Run a macro from VBA

Hi!


I'm trying to write a VBA code to:


From workbook_x it opens workbook_y and then run the macros (macro1 and macro2) that are stored in workbook_y.


I tryed this: (its written in workbook_x's VBE)


' Workbooks.Open ("U:workbook_y.xlsm")

Windows("workbook_y.xlsm").Activate


Application.AutomationSecurity = msoAutomationSecurityLow


Application.Run "workbook_y.xlsm!Module1.macro1"

Application.Run "workbook_y.xlsm!Modeule2.macro2" '


But an error message appeared.


Can anyone help me?


Thanks!
 
Hi, irisqueiroz!

Just as a blind shot, shouldn't it be:

Application.Run "workbook_y.xlsm!Module2.macro2" '

instead of:

Application.Run "workbook_y.xlsm!Modeule2.macro2"

?

Regards!
 
Yes, SirJB7!


But neither the first macro runs...

The error is: 'Run-Time Error '1004': its not possible to execute a macro because it might not be available or all macros can be desabled...
 
Hi, irisqueiroz!

The rigor questions:

a) Have you enabled macros or files are in trusted folders or do they have signed certificates? If you don't set any trusted folder from the Options menu and you didn't set to use digitally signed macros, and you still don't get asked to enable macros, please check macro security options settings.

b) Are there any previous Application.DisplayAlerts statement set to false, since you started that Excel instance?

c) If none satisfactory explanation to both of the above, you know the routine, sample files (all), upload, ...

Regards!
 
Hi, irisqueiroz!


For Excel version 2010, from the menu, File, Options, Trust Center (or however it's in your version, the last option), Trust Center Setup, and then:

a) Trusted Locations: 2nd option, adjust list as required

b) Trusted Documents: 3rd option, check first item, uncheck second

c) Complements: 4th option, all items unchecked

d) ActiveX Setup: 5th option, select ask before enabling all controls with minimum restrictions and check safe mode

e) Macro Setup: 6th option, select disable all macros with notification and check trust in access to VBA project object model


If not solved after this, please proceed as option c) of my previous post.


Regards!
 
Hi, irisqueiroz!


That is done for the Excel application, not just for individual files.

Option c) is uploading a sample file, in this case both files, the one that has the code

that calls workbook_y (workbook_x) and the called workbook_y. You did it before, didn't you?


Regards!
 
@irisqueiroz


Hi


It is better to upload a sample file other wise please mention the full code of both workbooks including Module1 and Module2


i think there is some thing mistake in the Module2 (Macro2) because with above mention code you told first macro is working fine but not the 2nd macro


Thanks


SP
 
I have tested following code and it works fine for me.

See if it works for you.

[pre]
Code:
Public Sub TestCode()
Dim wbCode As Workbook: Set wbCode = Workbooks.Open("D:workbook_y.xlsm")
Dim strRun As String: strRun = wbCode.Name & "!Module1.RunMyMacro"
Application.Run strRun
End Sub
[/pre]

SP: None of the macros is working is what OP has said.
 
Hi, irisqueiroz!

You have done it before, trust me! Ha ha ha... check this link:

http://chandoo.org/forums/topic/vba-sum-procedure#post-37221

However here you have the guidelines:

http://chandoo.org/forums/topic/posting-a-sample-workbook

Regards!
 
Back
Top