|
|
|
|
|
|
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:
|
- Copy the code above.
- Open Word.
- Hit Alt+F11 to open the Visual Basic Editor.
- Double-click Project Normal at the left.
- Choose Insert-Module, and paste the code into the window at the right.
- Hit the Save diskette button and close the VBE.
|
Test the code:
|
- Open any document that contains code.
- Hit Tools-Macro-Macros and double-click DeleteAll.
|
Sample File:
|
No Attachment
|
Approved by Anne Troy
|
This entry has been viewed 125 times.
|
|