Friday, March 23, 2018

excel - Using Application.Run to open a workbook with protected worksheets and protected VBAProject

An employee at one of my company's local offices is working on a macro in Sheet1 of a workbook that would run a macro in another workbook using Application.Run:



Private Sub CommandButton1_Click()
Wfile = Range("B2").Value

Wpath = Range("B3").Value

Workbooks.Open Wpath + "/" + Wfile
Application.Run Wfile & "!copy_rates_macro"

End Sub


The workbook that he is trying to open/use is protected in every way possible (all of its sheets are protected and its VBAProject is protected as well.




When the macro is run, the 1004 run-time error message window pops up saying "Cannot rund the macro 'Name.xlsm!copy_rates_macro'. The macro may not be available in this workbook or all macros may be disabled.'



I did a lot of research and I thought the putting the following in the protected file would work:



Private Sub Workbook_Open()
' Dim wSheet As Worksheet
' For Each wSheet In Worksheets
' wSheet.Protect Password:="pw", UserInterFaceOnly:=True
' Next wSheet
Application.EnableEvents = False

End Sub


Note that the parts commented out above are my additions to code that was already there and must remain there. Also, "pw" is the password for every worksheet and the VBAProject.



This code didn't make a difference (it wasn't commented out when I ran it), and I imagine it has something to do with the VBAProject being protected.



Is this request even possible, or is it a lost cause? My boss doesn't want the password to the protected workbook to be released but I can't see a way around it.



Thanks for any help.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...