I have the following VBA code that unprotects a Project in a different workbook then deletes the existing module.
I then want it to unprotect the project that the current macro is running in to copy the module over to the other workbook.
Sub add_etc()
Dim DProj As Object
Set DProj = ActiveWorkbook.VBProject
Application.VBE.MainWindow.Visible = True
For Each OpWin In DProj.VBE.Windows
If InStr(OpWin.Caption, "(") > 0 Then OpWin.Close
Next OpWin
Application.SendKeys "pword", True
Application.SendKeys "~", True
' Delete existing module
DProj.VBE.selectedvbcomponent.Activate
Application.VBE.activevbproject.VBComponents.Remove
Application.VBE.activevbproject.VBComponents("AD_Macros")
' Unprotect source file project
aaa = ThisWorkbook.Name
Workbooks(aaa).Activate
Dim SProj As Object
Set SProj = ActiveWorkbook.VBProject
For Each OpWin In SProj.VBE.Windows
If InStr(OpWin.Caption, "(") > 0 Then OpWin.Close
Next OpWin
Application.VBE.MainWindow.Visible = True
Application.SendKeys "test", True
Application.SendKeys "~", True
VBProj.VBE.selectedvbcomponent.Activate
' Copy module in
' Next bit of code works okay
End Sub
The code works until it gets to the
' Unprotect source file project
when the sendkeys function is sending to the Excel spreadsheet instead of the project. I think it may be something to do with the OpWin.Caption (gained from a previous post) as I don't quite understand what it means in English!
This is the culmination of several of my recent posts and if you can crack this for me I would be delighted.
I then want it to unprotect the project that the current macro is running in to copy the module over to the other workbook.
Sub add_etc()
Dim DProj As Object
Set DProj = ActiveWorkbook.VBProject
Application.VBE.MainWindow.Visible = True
For Each OpWin In DProj.VBE.Windows
If InStr(OpWin.Caption, "(") > 0 Then OpWin.Close
Next OpWin
Application.SendKeys "pword", True
Application.SendKeys "~", True
' Delete existing module
DProj.VBE.selectedvbcomponent.Activate
Application.VBE.activevbproject.VBComponents.Remove
Application.VBE.activevbproject.VBComponents("AD_Macros")
' Unprotect source file project
aaa = ThisWorkbook.Name
Workbooks(aaa).Activate
Dim SProj As Object
Set SProj = ActiveWorkbook.VBProject
For Each OpWin In SProj.VBE.Windows
If InStr(OpWin.Caption, "(") > 0 Then OpWin.Close
Next OpWin
Application.VBE.MainWindow.Visible = True
Application.SendKeys "test", True
Application.SendKeys "~", True
VBProj.VBE.selectedvbcomponent.Activate
' Copy module in
' Next bit of code works okay
End Sub
The code works until it gets to the
' Unprotect source file project
when the sendkeys function is sending to the Excel spreadsheet instead of the project. I think it may be something to do with the OpWin.Caption (gained from a previous post) as I don't quite understand what it means in English!
This is the culmination of several of my recent posts and if you can crack this for me I would be delighted.