View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Removing a module

You sure it didn't say VBComponent (not VBProject)???

I got a compile error if I didn't add that reference (tools|references within
the VBE).

Another problem that could occur is that the module isn't removed because:

Tools|Macro|Security|Trusted Publishers tab
Trust access to Visual Basic Project

is unchecked.

I didn't get an error in my test. The "on error resume next" line suppressed
it.

And this security setting is a user by user setting--not something a developer
can change via code.

Candyman wrote:

Is there a difference in code going to Excel 2003?

I have the code to remove a module:

Private Sub RemoveModule(mName As String)
Dim objVBComp As VBComponent
If modExists(mName) = True Then
Set objVBComp = ThisWorkbook.VBProject.VBComponents(mName)
ThisWorkbook.VBProject.VBComponents.Remove objVBComp
End If
End Sub
'Before using these procedures, you'll need to set a reference in VBA to the
'VBA Extensibility library. In the VBA editor, go to the Tools menu, choose
'the References item, and put a check next to "Microsoft Visual Basic For
'Applications Extensibility" library.

Function modExists(modName As String) As Boolean
On Error Resume Next
modExists = Len(ThisWorkbook.VBProject.VBComponents(modName).N ame) < 0
End Function

The code does not remove it and has a cannot recognize vbProject in workbook
error. What is wrong?

Thanks


--

Dave Peterson