Solved

scripting macro addition to normal.dot

Posted on 2011-09-08
9
387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

690 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