S Oberlander
Board Regular
- Joined
- Nov 25, 2020
- Messages
- 157
- Office Version
- 365
- Platform
- 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:
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:
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