Home

VBA to trust macro in another workbook

%3CLINGO-SUB%20id%3D%22lingo-sub-809303%22%20slang%3D%22en-US%22%3EVBA%20to%20trust%20macro%20in%20another%20workbook%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-809303%22%20slang%3D%22en-US%22%3E%3CP%3EI%20know%20how%20to%20use%20VBA%20to%20open%20another%20workbook.%20However%2C%20if%20the%20opened%20workbook%20is%20macro-enabled%20and%20NOT%20being%20trusted%20before%2C%20is%20it%20possible%20to%20open%20it%20with%20trust%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20there%20are%20two%20files.%20%22Control.xlsm%22%20and%20%22Target.xlsm%22.%20In%20%22Target.xlsm%22%2C%20there%20is%20macro%20%22Gen_Square%22%20to%20generate%20the%20square%20of%20the%20row%20number%20for%201st%20to%20100th%20row.%20When%20I%20am%20using%20%22Control.xlsm%22%20to%20open%20%22Target.xlsm%22%20and%20run%20the%20statement%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Workbooks(%22Target.xlsm%22).Application.Run(%22Gen_Square%22)%3C%2FP%3E%3CP%3EIt%20fails%20as%20the%20workbook%20%22Target.xlsm%22%20is%20not%20trusted%20before.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-809303%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-810107%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20to%20trust%20macro%20in%20another%20workbook%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-810107%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F53148%22%20target%3D%22_blank%22%3E%40Man%20Fai%20Chan%3C%2FA%3E%26nbsp%3BThis%20behaviour%20is%20by%20design%20and%20it%20is%20meant%20to%20protect%20you.%20If%20it%20were%20possible%20to%20trust%20another%20macro-enabled%20workbook%2C%20just%20by%20opening%20it%20using%20a%20trusted%20file's%20VBA%2C%20that%20could%20be%20exploited%20by%20people%20with%20malicious%20intent%20and%20wreak%20havoc.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20if%20you%20want%20to%20run%20the%20code%20in%20the%20other%20workbook%2C%20trust%20it%20first.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

I know how to use VBA to open another workbook. However, if the opened workbook is macro-enabled and NOT being trusted before, is it possible to open it with trust?

 

For example, there are two files. "Control.xlsm" and "Target.xlsm". In "Target.xlsm", there is macro "Gen_Square" to generate the square of the row number for 1st to 100th row. When I am using "Control.xlsm" to open "Target.xlsm" and run the statement

                                    Workbooks("Target.xlsm").Application.Run("Gen_Square")

It fails as the workbook "Target.xlsm" is not trusted before. 

 

Thank you. 

1 Reply

@Man Fai Chan This behaviour is by design and it is meant to protect you. If it were possible to trust another macro-enabled workbook, just by opening it using a trusted file's VBA, that could be exploited by people with malicious intent and wreak havoc.

 

So, if you want to run the code in the other workbook, trust it first.

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
9 Replies