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

Editing Word Macros with VBA/Script

Status
Not open for further replies.

cfjdugan

MIS
Aug 16, 2002
7
GB
Hi Folks,

Is it possible to edit an existing Word macro (contained in the Normal.dot) using VBA/Script?

We are moving from locally saved templates to server based but I need to update the paths on the existing macros on each machine first, I'll train users to use the correct method (File>Open>Templates on My Computer)now and as machines get replaced I'll remove the macro and their toolbar buttons and rely on the GPO to set the workgroup templates location.

Thanks,

Chris
 
Is it possible to edit an existing Word macro (contained in the Normal.dot) using VBA/Script?"

Yes. Use the editor. Alt-F11 gets you into the VBE (Visual Basic Editor). Or Tools > Macro > Visual Basic Editor.

I have some comments though.

Putting macro code in Normal.dot is a bad idea. Even Microsoft itself recommends that code not be put into Normal.dot. Unfortunately that is the default location.

"We are moving from locally saved templates to server based "

Good idea, and all the more reason to NOT use Normal.dot, but a global template (a code container) that is on a server.

Gerry
 
Thanks Gerry,

I realise that i can manually edit the macro that's why I asked if it was possible to do it with VBA or VBScript as I have about 110 computers to update? It would be helpful if anyone has any code snippets for doing something similar.

I have tinkered about with VBscript in the past (network admin stuff) so feel confident that i can get it to work provided there is a way to do it and I can get some pointers on how to do it. I may have to start researching viruses as macro viruses do this sort of thing all the time.

I can't find a way to do this after looking at the help pages within the VB editor or most other places I look.

"Putting macro code in Normal.dot is a bad idea. Even Microsoft itself recommends that code not be put into Normal.dot. Unfortunately that is the default location."

I realise that you shouldn't store customisations within normal.dot but that's what I inherited, so I have to sort it out as best I can :)

--
Chris
 
I may have to start researching viruses as macro viruses do this sort of thing all the time."

"I can't find a way to do this after looking at the help pages"

I am not following yet...do....WHAT, exactly?

Are you asking about how you would write code to alter code on 110 different, separate, machines?

Gerry
 
Hi Gerry,

"Are you asking about how you would write code to alter code on 110 different, separate, machines?"

Yes I am asking that but I have found a very likely way to do it now:


'How To Create and Call an Excel Macro Programmatically from VB'

The code in this Q article should be able to be modified to do what I need to do in either and AutoExec macro (saved in a Word or Excel document) or as part of a machine startup script.

--
Chris
 
Be sure and read the following section. You MUST manually change a security to allow VBA to be added this way. If you do so then you SHOULD reset the security. It's not a door you want left open.

"Additional Notes for Office XP
Office XP applications have a security option to allow programmatic access to the VBA object model. If this setting is "off" (the default), you may receive an error running the sample code. For more information about this setting and how you can correct the error, see the following article in the Microsoft Knowledge Base:
282830 ( ) PRB: Programmatic Access to Office XP VBA Project Is Denied "
 
You MUST manually change a security to allow VBA to be added this way.

You CAN change this setting in code, but it does not change it for the current session, only for future ones ...

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Let me reiterate what fumei said regarding the store location of macros. Normal.dot resides locally, and thus is not backed up in most office environments.
 
Except for environments where they push normal.dot down to the local machine when you log on to the network. Yes, it is still local, but managed from the network.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top