Solved

scripting macro addition to normal.dot

Posted on 2011-09-08
9
378 Views
Last Modified: 2012-05-12
We are trying to automate the addition of a macro into Word's Normal.dot.  Our users need a signature file macro that is unique to each.  I have the visual basic code that needs to go in and can perform the scripting via vbscript, just don't have the knowledge on how to vbscript the insertion of the macro.  
I realize it's not as easy as opening up Normal.dot and copying in the code.  

Does anyone know how to script the opening ot the vb editor within word?  
0
Comment
Question by:Pat_S
  • 5
  • 4
9 Comments
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 500 total points
ID: 36510231
Create a master document containing the macro code you want to insert in a separate module (modStuart in this example), and save is as Master.docm (or whatever).

In Word you don't need to access the VBA IDE to add code to normal.dot - there is a method called OrganizerCopy which can do it, so your VBScript would be something like this:

Option Explicit

Dim wdApp
Dim objMaster
Dim strMasterDocFull
Const strMasterDocName = "Master.docm"
Const strMasterDocPath  = "C:\Documents and settings\YOURID\Desktop\" 
Const strModule = "modStuart"

strMasterDocFull = strMasterDocPath & strMasterDocName

Set objMaster = GetObject(strMasterDocFull)
Set wdApp = objMaster.Application

Call CopyModule

objMaster.Close 0  ' wdDoNotSaveChanges

wdApp.Quit


Sub CopyModule()
	
    Call wdApp.OrganizerCopy(strMasterDocFull, wdApp.NormalTemplate.FullName, strModule, 3)
    Call wdApp.NormalTemplate.Save


End Sub

Open in new window


Basically it opens your master document and using OrganizerCopy, puts your module into Normal.dotm (or .dot - not sure of your Word version, but it does not matter as the script uses the NormalTemplate property to get it whatever it's called.)

This needs some error handling (for example it fails if you already have a module called modStuart in normal) and tidying up, but I hope it will give you the principle.
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36510379
BTW you can copy styles and autotext in the same way - this method is what you get if you record yourself using the Templates and Addins Organizer dialog
0
 

Author Comment

by:Pat_S
ID: 36511251
thanx, Andrewssd3.  I will give it a shot.  we are on word 2002 and 2003.  
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36511379
OK - I tested this on 2007, but I have used it in the past on 2003, so I think it should be fine
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Pat_S
ID: 36512338
andrewssd3,
if the module does not exist, will it be created when i copy the contents?  

i'm thinking i could use your method to pull over all the macros, autotext, styles, etc from the old xp office normal.dot to the new windows 2003 normal.dot.  

thanx for your help, i'll let you  know how it works out.  
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36512390
Yes it copies the whole module - in fact it must not already be there or it errors.  And yes you could use it to copy everything - take a look at the template organizer - it's not very user friendly but it does the job.  If you haven't seen it it's on Tools, Templates and add-ins, Organizer...
0
 

Author Comment

by:Pat_S
ID: 36512604
so, where you have strmodule = "modStuart", I can replace that with "styles" or "autotext" and just repeat the call to wdapp.organizercopy?  

0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36512657
Yes, the name and the last parameter, which identifies the type of object you want to move - have alook at the online documentation for OrganizerCopy, or record some macros of yourself doing different things - that's how I got the code.
0
 

Author Comment

by:Pat_S
ID: 36512917
YOU ARE THE FRICKEN GREATEST!!!!!!!!!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now