Solved

scripting macro addition to normal.dot

Posted on 2011-09-08
9
377 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

743 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

10 Experts available now in Live!

Get 1:1 Help Now