Run a macro in a form from a macrobutton or text form field

M

Mary

I have a form, saved as a document template, that I want
users to enter information into. I attempted to have a
text form field that runs a macro on entry to print
labels. The macro works when the form is protected and I
run it from Tools-Macro, but when I unprotect the form I
can't run the macro from the text form field.

I need to unprotect the form so users can enter their
information. The error I usually get seems to be about
the logic: ActiveDocument.Close (and things like that).
I also tried using a macrobutton field, but that also
doesn't work when I unprotect the form.

How can I get the user to run the macro that prints
labels?

I'm using Microsoft Word 2002. I'd be very grateful for
any help!
 
J

Jean-Guy Marcil

Mary was telling us:
Mary nous racontait que :
I have a form, saved as a document template, that I want
users to enter information into. I attempted to have a
text form field that runs a macro on entry to print
labels. The macro works when the form is protected and I
run it from Tools-Macro, but when I unprotect the form I
can't run the macro from the text form field.

This is by design. OnExit and OnEntry macros only work when the document is
protected for forms, like the dropdown only drops when it is protected...
I need to unprotect the form so users can enter their
information. The error I usually get seems to be about

??? The whole point of using forms is to protect them so that users can
enter information. I do not understand why you need to unprotect it so that
users can enter information.... Very weird!
the logic: ActiveDocument.Close (and things like that).

Now you are writing about an error in a macro?
You started with the fact that the macro would not run. If it does not run,
there cannot be an error. So, what do you mean here?
I also tried using a macrobutton field, but that also
doesn't work when I unprotect the form.

It should.
Macrobutton fields work regardless of the protection level. Are you clicking
or double clicking?
How can I get the user to run the macro that prints
labels?
I'm using Microsoft Word 2002. I'd be very grateful for
any help!

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

Jeremy

Hey all.

I'm trying to make a template for people to use at work. The basic idea is
an invoice template. I want to make it so that people can open the file in
a read only type format, fill in there details, and then save a copy of it
to another folder.

So...my question is.....

A lot of the people at work just don't seem to remember to change the
directory to a different path. I'd like to make a button of some kind at
the bottom of the document that says "Click here to Save."

So...I'm assuming its some kind of macro, but I can't seem to figure out how
to use them. Ideally the save-as box would pop up and all they have to do
is type in the file name. Or...even better....could I have it linked
somehow to the invoice number that is on the page already (one of the
required input fields) so that when they hit this save button, it
automatically saves the file as the invoice number.doc in my specified
directory on another drive?

Any tips and exaples would be greatly appreciated.

Jeremy
 
J

Jeremy

I've created a macro that I borrowed from the newsgroup:

Sub macro1()
'
' macro1 Macro
' Macro created 5/25/2005 by Jeremy
'
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogFileSaveAs)
With oDlg
.Name = "C:\Jer-Pictures\My Pictures\motorcycles" ' the directory
.Show
End With

End Sub


And then...in my document I found this command to make my button:



{MACROBUTTON Macro1 Click here to save}



And those seem to be working so far. So...the only thing I need to figure
out how to do now to make this perfect is figure out how to link the save-as
command, to a field box that is in my document...so it automatically saves
the files as the invoice number without prompting for a file name.



And I guess the second thing would be figure out how to customize the look
of the button I created, maybe make it a single click instead of a double
click or something.



Thanks for the help,

Jeremy
 

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