VBA to unlock the module that the VBA is running in!

dawsona

Board Regular
Joined
Jul 28, 2002
Messages
66
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?
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Watch MrExcel Video

Forum statistics

Threads
1,123,474
Messages
5,601,872
Members
414,479
Latest member
Beau the dog

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
Top