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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing Macros with other Macros 1

Status
Not open for further replies.

DLG0311

Technical User
Jan 6, 2005
13
0
0
GB
I need to remove 2 macros from a Word Doc before circulating it (size reasons as well as nosey/tampering users!) I don't want to remove the whole Module (easy?), because the macro to remove the macros is in it.

I have tried the following but it doesnt work. The path does but the "Name" won't pick up the macro names.

Where is the flaw, or is the code wrong anyway?

Sub DTidy()
Application.OrganizerDelete Source:=ActiveDocument.Path & "\" & ActiveDocument.Name, _
Name:="DFill", Object:=wdOrganizerObjectProjectItems
Application.OrganizerDelete Source:=ActiveDocument.Path & "\" & ActiveDocument.Name, _
Name:="DClean", Object:=wdOrganizerObjectProjectItems
End Sub
 
You can use this to delete the first 3 lines in the module "module1".

Code:
Sub DeleteSub()
    Application.VBE.ActiveVBProject.VBComponents("Module1") _
        .codemodule.DeleteLines 1, 3
End Sub

The 1 corresponds to the line to start deleting and the 3 is the number of lines you wish to delete.

HTH,
Eric
 
Thanks Luceze, but I don't understand how that will help me delete two out of three Macros in Word which are all in the Modules/NewMacros "directory".

Perhaps you could clarify for me.

Thanks very much.

Darryll
 
Hey Darryll,

I am assuming that the macros that you are trying to delete always appear in the same order.

In that case, if the the first 50 lines in the module "NewMacros" comprise the first two macros then this will delete the first fifty lines.
Code:
Application.VBE.ActiveVBProject.VBComponents("NewMacros").CodeModule.DeleteLines 1, 50

If the two macros are in lines 20-30 and lines 1-10 then this will do it.
Code:
Application.VBE.ActiveVBProject.VBComponents("NewMacros").CodeModule.DeleteLines 20, 10
Application.VBE.ActiveVBProject.VBComponents("NewMacros").CodeModule.DeleteLines 1, 10

HTH,
Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top