Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Removing a module

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default Removing a module

I've been using the following code for several years (from XL 97 to 2003)
without issue. I dim the variables as objects so that I can avoid using the
VB6 extensibility reference (the versioning of this library caused some
issues around the time of 97).

Dim wkb As Workbook
Dim vbcsT As Object
Dim vbcT As Object

set wkb = ActiveWorkbook

' If module exists, remove it
If ModuleExists(strModule) Then
Set vbcT = wkb.VBProject.VBComponents(strModule)
Call wkb.VBProject.VBComponents.REMOVE(vbcT)
End If



"Dave Peterson" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Removing a module

I did not know the part about diming the variables and the VB6 extensibility.
Thanks! Have a great day.

"Bill Pfister" wrote:

I've been using the following code for several years (from XL 97 to 2003)
without issue. I dim the variables as objects so that I can avoid using the
VB6 extensibility reference (the versioning of this library caused some
issues around the time of 97).

Dim wkb As Workbook
Dim vbcsT As Object
Dim vbcT As Object

set wkb = ActiveWorkbook

' If module exists, remove it
If ModuleExists(strModule) Then
Set vbcT = wkb.VBProject.VBComponents(strModule)
Call wkb.VBProject.VBComponents.REMOVE(vbcT)
End If



"Dave Peterson" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Removing a module

I did not have the security - trust access to Visual Basic Project checked.
good point. My code was cut and paste, my error message was from memory (not
Memorex). this sounds like the ticket. Thanks!

"Dave Peterson" wrote:

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Module Protection Programatically Adam Excel Discussion (Misc queries) 8 April 17th 06 05:46 AM
Removing & Importing a macro module Glen Mettler[_4_] Excel Programming 3 June 18th 05 09:32 PM
Using Excel 2003 SP1 - Removing a VBA module closes Excel Greg on DBear Excel Programming 0 May 30th 05 12:04 PM
Removing a module with a macro bb Excel Programming 1 December 22nd 04 02:07 PM
Removing a module with code KimberlyC Excel Programming 2 January 13th 04 09:51 PM


All times are GMT +1. The time now is 03:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"