How do I create a button in a word template that will run a macro

L

Lobo

I Have four fields that need to be updated when the template is opened and I
have recorded a macro
Selection.WholeStory
Selection.Fields.Update
Selection.HomeKey

Now I want to display a button that the user can click to run this macro so
he can update the fields.

is it also possible to print the pages individualy to individual pdf files
via a macro to be attached to an email later?

Thanks
 
J

Jezebel

Right-click any toolbar. Select customize. On the Commands tab select Macros
in the Categories list. Select your macro from the Commands list and drag it
to the toolbar yuou want.

Separately, that's a pretty lousy way to update the fields. You could just
use this line in place of what you currently have --

ActiveDocument.Fields.Update

But are you aware that your code (and this one-line equivalent) updates
fields only in the body of the document, not in headers, footers, textboxes,
etc? If you want to update all fields, wherever they are, use --

Dim pRange as Word.Range

For each pRange in ActiveDocument.StoryRanges
Do
pRange.Fields.Updatge
Set pRange = pRange.Next
Loop until pRange is nothing
Next
 
L

Lobo

Jezebel,

Thanks for the help, I'm just new to all this Macro writing, therefore my
bad macro.

I did not want the Button on the tool bar but in the document , so that it
is only available when that Template gets opened.

I have put in a command button object , that works

Now I need to be able to print each page seperately , and if possible with
the file name as one of the fields that was input previously

thanks
 

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