Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove macro from word programmatically

Status
Not open for further replies.

riska

Programmer
Apr 16, 2002
7
CZ
Have anybody suggestions how to remove macro from word document programmatically?

The macro create is called when the new instance of word document is created. This macro parse some data into document.

But I need to remove this macro from document when it ends. Then it isn't usefull and causes message for user about viruses protection.

Thanks. riska
 
Hi

Is this what you are refering to?


Sub CreateAndRemove()
Dim FileSaveAsName As String
Application.DisplayAlerts = False
With ThisDocument.VBProject.VBComponents
.Remove .Item("Module1")
End With
FileSaveAsName = "c:\my documents\myFileName.doc"
ActiveDocument.SaveAs FileSaveAsName
ActiveDocument.Save
Application.Quit
End Sub


rgrds
LSTAN
 
thanks,

it helps me and I found out how to delete, macro on "This Document" :

Dim countOfLines As Integer

countOfLines = ThisDocument.VBProject.VBComponents.Item("ThisDocument").CodeModule.countOfLines

ThisDocument.VBProject.VBComponents.Item("ThisDocument").CodeModule.DeleteLines _
startline:=1, Count:=countOfLines

riska
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top