I had a question about unlocking a VBA project answered recently but now it has grown another step.
I have a workbook that has two modules in it. The first module is code to copy the second module into another workbook.
Both the source file and the destination workbook have their VBA projects password protected which means that I have to unlock the source before it will let me copy the module to the receiving workbook.
Code so far (which obviously dosen't work) is below:
Sub aaa()
' Copy module in
Dim wbproj As Object
Set wbproj = ActiveWorkbook.VBProject
Application.SendKeys "pword1", True
Application.SendKeys "~", True
wbproj.VBE.selectedvbcomponent.Activate
Dim mySource As String
Dim myDestination As String
mySource = ThisWorkbook.Name
myDestination = ActiveWorkbook.Name
Dim wbbproj As Object
Set wbbproj = ThisWorkbook.VBProject
wbbproj.VBE.selectedvbcomponent.Select
Application.SendKeys "test", True
Application.SendKeys "~", True
With Workbooks(mySource)
modname = .Path & "code.txt"
Application.DisplayAlerts = False
.VBProject.VBComponents("AD_Macros34").Export modname
End With
Workbooks(myDestination).VBProject.VBComponents.Import modname
Kill modname
End Sub
The problem appears to be the line:
Set wbbproj = ThisWorkbook.VBProject
as it is not unprotecting the source module.
Can anyone help?
I have a workbook that has two modules in it. The first module is code to copy the second module into another workbook.
Both the source file and the destination workbook have their VBA projects password protected which means that I have to unlock the source before it will let me copy the module to the receiving workbook.
Code so far (which obviously dosen't work) is below:
Sub aaa()
' Copy module in
Dim wbproj As Object
Set wbproj = ActiveWorkbook.VBProject
Application.SendKeys "pword1", True
Application.SendKeys "~", True
wbproj.VBE.selectedvbcomponent.Activate
Dim mySource As String
Dim myDestination As String
mySource = ThisWorkbook.Name
myDestination = ActiveWorkbook.Name
Dim wbbproj As Object
Set wbbproj = ThisWorkbook.VBProject
wbbproj.VBE.selectedvbcomponent.Select
Application.SendKeys "test", True
Application.SendKeys "~", True
With Workbooks(mySource)
modname = .Path & "code.txt"
Application.DisplayAlerts = False
.VBProject.VBComponents("AD_Macros34").Export modname
End With
Workbooks(myDestination).VBProject.VBComponents.Import modname
Kill modname
End Sub
The problem appears to be the line:
Set wbbproj = ThisWorkbook.VBProject
as it is not unprotecting the source module.
Can anyone help?