Solved

scripting macro addition to normal.dot

Posted on 2011-09-08
9
383 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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
 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

839 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