Word

Remove All VBA from Document

Ease of Use

Easy

Version tested with

2000 

Submitted by:

smozgur

Description:

Removes all VBA code from the document that is active at the time the code is run. 

Discussion:

You may have or receive files that contain code. You don?t know what the code is for and you don?t want the code in the document. Or you regularly record macros in documents and then later want to delete the code from the documents. Use this code to completely clear a document of all VBA. The code must be placed in your normal.dot file so that it can be safely used on other files. You can use this code to clean code from any Word document except normal.dot. The document must be open on your screen when you run the macro. (From "Dreamboat on Word", a book by HolyMacro! Books.) 

Code:

instructions for use

			

Option Explicit Public Sub DeleteAllVBA() Dim vbComp As Object For Each vbComp In ActiveDocument.VBProject.VBComponents With vbComp If .Type = 100 Then .CodeModule.DeleteLines 1, .CodeModule.CountOfLines Else ActiveDocument.VBProject.VBComponents.Remove vbComp End If End With Next vbComp End Sub

How to use:

  1. Copy the code above.
  2. Open Word.
  3. Hit Alt+F11 to open the Visual Basic Editor.
  4. Double-click Project Normal at the left.
  5. Choose Insert-Module, and paste the code into the window at the right.
  6. Hit the Save diskette button and close the VBE.
 

Test the code:

  1. Open any document that contains code.
  2. Hit Tools-Macro-Macros and double-click DeleteAll.
 

Sample File:

No Attachment 

Approved by Anne Troy


This entry has been viewed 125 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express