Optmimizing OrganizerDelete, OrganizerCopy, Finding Modules in Templates

  • Thread starter Michael Ripberger
  • Start date
M

Michael Ripberger

I am interested in optimizing the code below. The Word object model doesn't
seem to have a way to "see" if the Normal template has these 4 module in it
already. So I am forced to delete them and then re-copy them--this takes 5-6
seconds each time Word starts up. It would be quicker to query for them
first somehow and only copy the ones that weren't there. If I try to copy
and the module already exists, word raises an error. Any help would be
appreciated.

With Application
.OrganizerDelete Application.NormalTemplate.FullName, _
"AutoClose", wdOrganizerObjectProjectItems
.OrganizerDelete Application.NormalTemplate.FullName, _
"AutoOpen", wdOrganizerObjectProjectItems
.OrganizerDelete Application.NormalTemplate.FullName, _
"NORMALAutoClose", wdOrganizerObjectProjectItems
.OrganizerDelete Application.NormalTemplate.FullName, _
"NORMALAutoOpen", wdOrganizerObjectProjectItems
End With

With Application
.OrganizerCopy strAutoMacroTemplate,
NormalTemplate.FullName, _
"NORMALAutoClose", wdOrganizerObjectProjectItems
.OrganizerCopy strAutoMacroTemplate,
NormalTemplate.FullName, _
"NORMALAutoOpen", wdOrganizerObjectProjectItems
.OrganizerRename NormalTemplate.FullName, "NORMALAutoClose",
_
"AutoClose", wdOrganizerObjectProjectItems
.OrganizerRename NormalTemplate.FullName, "NORMALAutoOpen",
_
"AutoOpen", wdOrganizerObjectProjectItems
End With
 
J

Jonathan West

Hi Michael,

The simplest way is to include this line at the start of your macro

On Error Resume Next

This will cause the macro to ignore an error resulting from trying to copy a
module that already exists, and simply go on to execute the next line of
code.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top