Remove Modules not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have the following code which should remove modules have it doesn't seem
to work unless I step through it using F8.

Activesheet.cmdSendEmail.Visible = True
Application.SendKeys ("%te" & "^{TAB}" & "{TAB}{DEL}" & "{TAB}{DEL}" &
"{ENTER}")
Call RemoveModules
Cells.Select
Selection.Locked = True
Range("B6").Select
Call ProtectSheet
ActiveWorkbook.SaveAs "C:\Adv.xls"
MsgBox "CLICK EMAIL BUTTON", vbOKOnly

Any suggestions would be very much appreciated.

Thanks
Noemi
 
What is in the procedure RemoveModules?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Here is the procedure

Public Sub RemoveModules()
Dim vbproject As vbproject
Dim VBComp As VBComponent
Dim vbcomp1 As VBComponent
Dim vpcom2 As VBComponent
Dim vpcomp3 As VBComponent
Dim vpcomp4 As VBComponent
Dim vpcomp5 As VBComponent
Set vbproject = ThisWorkbook.vbproject
Set VBComp = ThisWorkbook.vbproject.vbcomponents("Module3")
Set vbcomp1 = ThisWorkbook.vbproject.vbcomponents("Module4")
Set vbcomp2 = ThisWorkbook.vbproject.vbcomponents("Module6")
Set vbcomp3 = ThisWorkbook.vbproject.vbcomponents("Module7")
Set vbcomp4 = ThisWorkbook.vbproject.vbcomponents("Module8")
ThisWorkbook.vbproject.vbcomponents.Remove VBComp
ThisWorkbook.vbproject.vbcomponents.Remove vbcomp1
ThisWorkbook.vbproject.vbcomponents.Remove vbcomp2
ThisWorkbook.vbproject.vbcomponents.Remove vbcomp3
ThisWorkbook.vbproject.vbcomponents.Remove vbcomp4
End Sub

Thanks
 
If that is the exact you are using, addition of "Option Explicit" at the top
of the module would be a good start.
Actually better, Tools>Options>Editor> check "Require Variable Declaration".

Use of a With would make it more readable.
And maybe a loop.

With ThisWorkbook.VBProject.VBComponents
For i = 3 To 8
.Remove .Item("Module" & i)
Next
End With

If using Excel 2002 or higher, make sure you have checked the
Tools>Macro>Security>Trusted Sources>"Trust access to Visual Basic Project"

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top