VBA to trust macro in another workbook

Iron 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.