Copy code from a protected VBA project

S Oberlander

Board Regular
Joined
Nov 25, 2020
Messages
147
Office Version
  1. 365
Platform
  1. Windows
I have this procedure to copy lines of code from a different workbook to the existing workbook, however the workbook being copied from has the vba project protected.
Is there any way around this? Unprotected the project is not an option.

Perhaps its possible to put these lines of code into a string in the code and write that into the existing workbook instead of copying a complete module?

Note the code works fine when I manually unprotect the project but I cannot have it unprotected for other users


Popup when trying to copy the module:

1634832808500.png


VBA Code:
Sub copycode()
'copies code from RP macro wrkbk thisworkbook code module to the active workbook
    Dim WB As Workbook
    Dim MWB As Workbook
    Dim WBCodeMod1 As Object, WBCodeMod2 As Object

    Set WB = ActiveWorkbook
    Windows("RP Macro Wrkbk.xlsb").Activate
    Set MWB = ActiveWorkbook
    ActiveWindow.Visible = False
    ' Copy the Workbook level Event handlers
    
    Set WBCodeMod1 = MWB.VBProject.VBComponents("ThisWorkbook").CodeModule
    Set WBCodeMod2 = WB.VBProject.VBComponents("ThisWorkbook").CodeModule
    WBCodeMod2.InsertLines 1, WBCodeMod1.Lines(1, WBCodeMod1.countoflines)
    
    
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I am at a loss why it is not functioning at your end.
I figured it out. I had renamed "VBAProject" as "Personal".
When I change ("VBAProject Properties...") to ("Personal Properties...") it works.
But I already published it the other way so I think I'll just leave it like that. I've got other stuff to tend to...

If you'll look on the header of my references box, it says Personal, while by yours it says VBAProject
 
Upvote 0
Ok ... that makes me feel a lot better knowing it does work on your end. Cheers !
 
Upvote 0
Dear @Logit,

I hope you could give me support as I'm trying to use the unlock function you attached in the first page, but I'm getting the same error @S Oberlander got.

I haven't changed the original function's code apart than adding two more "TABs" before entering the password for the first time in the properties window.
I have the same references activaded as @S Oberlander, except from "Ref Edit Control".

To put you in context, in the following thread I explained my goal and my problem (don't focus on the code as the unlock function is not the one that I'm currently using, which is actually the one from this thread) .


Thank you.

Best regards,

Marc
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top