saving vba scripts

A

abracad_1999

Is it possible to save a VBA script so that it is available to run
against any word doc that I open?

I click the save icon in the editor but it only seems to save the
script within the particular document that's open.

Only way I can transfer scripts across documents is to copy into a
text file, save that, then paste from it into the new document but
sure there must be a better way.
 
H

Helmut Weber

Hi,

many ways.
Just one:

Tools, Templates and Add-Ins...
Organizer...
Put in Normal, e.g. by way of
Copy
Delete


If you record a macro,
make sure normal is selected as the place where to store it.
Tools, macro, record new macro, store macro in.

There are other ways, using the
microsoft visual basic for applications extensibility library.
Don't know whether there are different version around
in what version of office.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

Ron Smith

A template is a good way to do that.

Create a new document and copy your VBA macros into that document. Then
select Save As and choose a Template (.dot) file.

It may be easiest to put it in the same directory as Normal.dot.

Anyway, you can then attach your template to any document with the Tools |
Templates and Add-ins | Attach button. If you find yourself doing this a
lot, create an "Attach template" macro in Normal.dot and associate it with a
keyboard combination. Then simply pressing that key combination attaches it
to your document. Here's the one I use:

Sub AttachGenealogy()
'
' AttachMyTemplate Macro
' Macro recorded 11/15/2003 by Ronald Q. Smith
'
With ActiveDocument
.UpdateStylesOnOpen = False ' (or true if you wish)
.AttachedTemplate = _
Options.DefaultFilePath(wdUserTemplatesPath) & "\MyTemplate.dot"
End With
End Sub

With this macro your template has to be in the default Templates directory
for Word. Obviously, you can put your own path there if you wish.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top