Solved

scripting macro addition to normal.dot

Posted on 2011-09-08
9
384 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
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…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

749 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