Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Removing modules via VBA

I am trying to use the following code (taken from a previous response to a
post by Bob Phillips) in a macro in my personal folder. It is attempting to
delete all the VBA modules in a target. I have tried to amend to only delete
modules unless its named "Print Routine". It is failing on the firsst line
of the For Next loop with Run Time Error 1004. I note that I am not sure
what role the variable VBComp is playing in the routine.

Dim VBComp As Object
Dim vbMod As Object
Dim RetainedModule As String

RetainedModule = "PrintRoutine"

For Each vbMod In ActiveWorkbook.VBProject.vbcomponents
If vbMod.Type = 1 And vbMod.Name = RetainedModule Then 'a module
with specific name
ActiveWorkbook.VBProject.vbcomponents.Remove vbMod
End If
Next vbMod

EM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Removing modules via VBA

It works fine for me. Have you enabled Trust access to visual basic project
in your security settings if you are using xl2002/3

I note that I am not sure
what role the variable VBComp is playing in the routine.


No role at all, but as you are looping VBComponents it would seem slightly
more logical to use VBComp instead of vbMod

Regards,
Peter T

"ExcelMonkey" wrote in message
...
I am trying to use the following code (taken from a previous response to a
post by Bob Phillips) in a macro in my personal folder. It is attempting

to
delete all the VBA modules in a target. I have tried to amend to only

delete
modules unless its named "Print Routine". It is failing on the firsst

line
of the For Next loop with Run Time Error 1004. I note that I am not sure
what role the variable VBComp is playing in the routine.

Dim VBComp As Object
Dim vbMod As Object
Dim RetainedModule As String

RetainedModule = "PrintRoutine"

For Each vbMod In ActiveWorkbook.VBProject.vbcomponents
If vbMod.Type = 1 And vbMod.Name = RetainedModule Then 'a module
with specific name
ActiveWorkbook.VBProject.vbcomponents.Remove vbMod
End If
Next vbMod

EM



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Removing modules via VBA

Yup that was it, did not have the trust enabled. Didn't even know the option
existed. Thanks.

EM

"Peter T" wrote:

It works fine for me. Have you enabled Trust access to visual basic project
in your security settings if you are using xl2002/3

I note that I am not sure
what role the variable VBComp is playing in the routine.


No role at all, but as you are looping VBComponents it would seem slightly
more logical to use VBComp instead of vbMod

Regards,
Peter T

"ExcelMonkey" wrote in message
...
I am trying to use the following code (taken from a previous response to a
post by Bob Phillips) in a macro in my personal folder. It is attempting

to
delete all the VBA modules in a target. I have tried to amend to only

delete
modules unless its named "Print Routine". It is failing on the firsst

line
of the For Next loop with Run Time Error 1004. I note that I am not sure
what role the variable VBComp is playing in the routine.

Dim VBComp As Object
Dim vbMod As Object
Dim RetainedModule As String

RetainedModule = "PrintRoutine"

For Each vbMod In ActiveWorkbook.VBProject.vbcomponents
If vbMod.Type = 1 And vbMod.Name = RetainedModule Then 'a module
with specific name
ActiveWorkbook.VBProject.vbcomponents.Remove vbMod
End If
Next vbMod

EM




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Removing modules via VBA

Hmmm...This works for me, except that using vbMod.Name = RetainedModule
means that the only module that IS deleted is the one you ostensibly
want to save (I'd think you'd want < instead).

VBComp doesn't play any role in the code you posted.

In article ,
ExcelMonkey wrote:

I am trying to use the following code (taken from a previous response to a
post by Bob Phillips) in a macro in my personal folder. It is attempting to
delete all the VBA modules in a target. I have tried to amend to only delete
modules unless its named "Print Routine". It is failing on the firsst line
of the For Next loop with Run Time Error 1004. I note that I am not sure
what role the variable VBComp is playing in the routine.

Dim VBComp As Object
Dim vbMod As Object
Dim RetainedModule As String

RetainedModule = "PrintRoutine"

For Each vbMod In ActiveWorkbook.VBProject.vbcomponents
If vbMod.Type = 1 And vbMod.Name = RetainedModule Then 'a module
with specific name
ActiveWorkbook.VBProject.vbcomponents.Remove vbMod
End If
Next vbMod

EM

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 VB Modules Automatically JNaugh Excel Programming 1 March 15th 06 07:00 PM
Public, Private, Event modules, Forms modules,,, Jim May Excel Programming 11 October 31st 05 03:12 AM
Basic question - modules and class modules - what's the difference? Mark Stephens[_3_] Excel Programming 9 May 8th 05 11:48 AM
When to code in sheet or userform modules and when to use modules Tony James Excel Programming 1 December 16th 04 10:02 PM
Class Modules vs Modules Jeff Marshall Excel Programming 2 September 28th 03 07:57 PM


All times are GMT +1. The time now is 05:01 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"