Command Button Macro

F

fiona

Hi All,

I have used VBA in Excel several times, so I'm trying to get a handle on it
in Word.

I have a template which I would like to save to a specific location after
people have filled it in. I have (with the help of this group) a macro which
does this, but I'd like to assign a command buton to it.

I have tried to draw in a command button and then copy and paste the macro
to it, but this doesn't seem to work and it also has a habit of making the
template open with the toolbox toolbar in the middle of the page and the
"edit" button pressed. This is very annoying and I can't seem to get rid of
it, even if I unclick the "edit" button and close the toolbox and then save
it again as a .dot template.

This is the macro (if it's important) which doesn't seem to work. It
basically doesn't run if I link it to the command button, but it does if I
keep it as a macro and then use the Macro/Run command.

Private Sub CommandButton1_Click()

'recorded by fiona to try to save this in the correct folder

FilePathName = "S:\Administration\Joanne\Travel\"
strDate = Format(Date, "ddmmyy")

ActiveDocument.SaveAs FileName:=FilePathName & Application.UserName &
strDate, FileFormat:=wdFormatDocument

End Sub

All the lines of working code are one line, this forum seems to have wrapped
it so ignore that. As I said, when it is actually a macro it works, when I
try to use it in a command button it doesn't. I've checked that the command
button's name is correct in the properties box.

Any help would be gratefully received.

Thanks,

Fiona
 
J

Jean-Guy Marcil

fiona was telling us:
fiona nous racontait que :
Hi All,

I have used VBA in Excel several times, so I'm trying to get a handle
on it in Word.

I have a template which I would like to save to a specific location
after people have filled it in. I have (with the help of this group)
a macro which does this, but I'd like to assign a command buton to it.

I have tried to draw in a command button and then copy and paste the
macro to it, but this doesn't seem to work and it also has a habit of
making the template open with the toolbox toolbar in the middle of
the page and the "edit" button pressed. This is very annoying and I
can't seem to get rid of it, even if I unclick the "edit" button and
close the toolbox and then save it again as a .dot template.

Since you are working from a template and that user will create documents
from the template, by far the easiest would be to create a toolbar with a
single button, or add a button to an existing toolbar.
Open the template > Tools > Customize > Commands tab > Macros on the left >
Find your macro in the list on the right > Drag and drop it on the toolbar
to create the button > Right click the button to access its properties
(Change its name, display text/picture, etc.).

Another advantage to that method is that the button will not print, it will
not take real-estate on the document itself and will always be visible to
the users, regardless of the page they are working on.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
F

fiona

Thanks Jean-Guy. A simple solution I often forget! It worked perfectly and
everyone who needs the template has access to the macro.
 

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