delete all code modules using VBA 
Author Message
 delete all code modules using VBA

In Word 2000, I have the following code to delete all code modules from a
document -- so I can
ensure that all macros are removed before I distribute it.

For each myComponent in ActiveDocument.VBProject.VBComponents
   If myComponent.Type = vbext_ct_ClassModule or myComponent.Type =
vbext_ct_StdModule Then
      ActiveDocument.VBProject.VBComponents.Remove (myComponent)
   End If
Next myComponent

The VBA object browser gives the signature for VBComponents.Remove as
   Remove(VBComponent As VBComponent)

But when I run the code,   I get the following error on the Remove method:
Run-time error '438' Object does not support this property or method

I've inspected the VBComponents and the code is attempting to remove the
code module, just as I intended.

Any ideas what's up?  Thanks for any help!

Lisa



Mon, 07 Feb 2005 12:09:52 GMT  
 delete all code modules using VBA
This is the code that worked:

For each myComponent in ActiveDocument.VBProject.VBComponents
   If myComponent.Type = vbext_ct_ClassModule or _
     myComponent.Type = vbext_ct_ClassModule or _
     myComponent.Type = vbext_ct_ClassModule Then
        Call Application.OrganizerDelete(ActiveDocument.Name, _
                                                           myComponent.Name,
_

wdOrganizerObjectProjectItems)
   End If
Next myComponent

When I save the resulting doc and re-open it, Word still thinks it has
macros.
If I say "okay, enable macros", I don't see anything in the project window .
. .

If anyone can answer this one ...  thanks!
Lisa


Quote:
> In Word 2000, I have the following code to delete all code modules from a
> document -- so I can
> ensure that all macros are removed before I distribute it.

> For each myComponent in ActiveDocument.VBProject.VBComponents
>    If myComponent.Type = vbext_ct_ClassModule or myComponent.Type =
> vbext_ct_StdModule Then
>       ActiveDocument.VBProject.VBComponents.Remove (myComponent)
>    End If
> Next myComponent

> The VBA object browser gives the signature for VBComponents.Remove as
>    Remove(VBComponent As VBComponent)

> But when I run the code,   I get the following error on the Remove method:
> Run-time error '438' Object does not support this property or method

> I've inspected the VBComponents and the code is attempting to remove the
> code module, just as I intended.

> Any ideas what's up?  Thanks for any help!

> Lisa



Tue, 08 Feb 2005 05:47:48 GMT  
 delete all code modules using VBA
Lisa,

once you've put macros in a word document or template, it will always
trigger the macro warning, even if you subsequently delete all of the code.
I seem to remember a KB article about this, but couldn't find it in a quick
search.  If you want a 'clean' document, you'll have to start with a new
document.

vty,
ssg


Quote:
> This is the code that worked:

> For each myComponent in ActiveDocument.VBProject.VBComponents
>    If myComponent.Type = vbext_ct_ClassModule or _
>      myComponent.Type = vbext_ct_ClassModule or _
>      myComponent.Type = vbext_ct_ClassModule Then
>         Call Application.OrganizerDelete(ActiveDocument.Name, _

myComponent.Name,
> _

> wdOrganizerObjectProjectItems)
>    End If
> Next myComponent

> When I save the resulting doc and re-open it, Word still thinks it has
> macros.
> If I say "okay, enable macros", I don't see anything in the project window
.
> . .

> If anyone can answer this one ...  thanks!
> Lisa



> > In Word 2000, I have the following code to delete all code modules from
a
> > document -- so I can
> > ensure that all macros are removed before I distribute it.

> > For each myComponent in ActiveDocument.VBProject.VBComponents
> >    If myComponent.Type = vbext_ct_ClassModule or myComponent.Type =
> > vbext_ct_StdModule Then
> >       ActiveDocument.VBProject.VBComponents.Remove (myComponent)
> >    End If
> > Next myComponent

> > The VBA object browser gives the signature for VBComponents.Remove as
> >    Remove(VBComponent As VBComponent)

> > But when I run the code,   I get the following error on the Remove
method:
> > Run-time error '438' Object does not support this property or method

> > I've inspected the VBComponents and the code is attempting to remove the
> > code module, just as I intended.

> > Any ideas what's up?  Thanks for any help!

> > Lisa



Mon, 14 Feb 2005 02:47:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How Do I Delete a Module Using VBA?

2. Deleting forms and modules in a backup database using VBA

3. Creating Modules in Access 97 using vba code

4. How to delete VBA modules from Word Template?

5. Code Module for Deleted Report

6. Deleting a Sub or Function from a Module via Code

7. Date Variable in VBA Code Module

8. Vba code which can execute FTP script from within the Access 97 module

9. Help: Compile and save all modules in Access runtime with VBA code

10. vba module code for deletion

11. Printing VBA code modules from Mac Word 98

12. Delete Table Field wit VBA code

 

 
Powered by phpBB® Forum Software