Saving as a designated file name

J

Jeremy

Thanks to everybody for the help, still have one outstanding issue that I
cannot figure out:

- My file is an invoice template for users to fill out
- The first text box with a bookmark around it is for the user to punch in
the invoice number.
- Below I've included the code that I'm using for them to click which
automatically saves the file to a designated path

- Now I just need to find a way to grab the data they enter into the invoice
number field, and use that to save the file as invoicenumber.doc.

- How do I edit my save macro to do this?

- Here is what I have so far:


Sub save()
'
' save Macro
' Macro created 6/5/2005 by Jeremy
'
ActiveDocument.SaveAs "C:\invoices\new invoices\"

UserForm1.Show


End Sub
 
J

Jay Freedman

Hi Jeremy,

You're missing a critical piece of information. You have to know the
name of the form field where the user types the invoice number (and
call it a "form field", not a "text box", because they're completely
different things).

To find out the name, unprotect the document and double-click the form
field (or click the Properties button on the Forms toolbar) to open
the field's Properties dialog. The name is in the "Bookmark" box in
the dialog. You can change it there if you want, so it describes what
goes into the field.

Once you know that name, you can change the macro like this, using the
actual name of the field in the quotes:

ActiveDocument.SaveAs "C:\invoices\new invoices\" _
& ActiveDocument.FormFields("InvoiceNum").Result _
& ".doc"
UserForm1.Show

(If you don't know about the underscore as a continuation character,
see http://www.word.mvps.org/FAQs/MacrosVBA/_AtEndOfLine.htm.)
 
J

Jeremy

Hey Jay.

Thanks for the help. That was the critical piece of info I've been looking
for. Apologies for my lack of grammar....I do understand the difference
between the formfield and a text box and I know how to adjust the
properties. I believe my document is pretty much complete. The only
problem now is that I did the entire thing as a regular word document and
not as a protected template. So...I'm assuming I'll be starting this one
all over. :)

Thanks though!
Jeremy
 
J

Jay Freedman

Glad it helped.

You can use File > Save As and change the "Save as type" dropdown at the
bottom of the dialog to "Template (*.dot)". That will do two things
automatically: change the extension to .dot and change the selected folder
to your Templates folder. Just hit OK and you have a template...
 
J

Jeremy

My form is all complete I'm just having trouble turning it into a template.
When I protect the form the entire document is frozen and I can't even enter
data into my text form fields.

The second problem...... As soon as I try to enter text into one of my
formfields (unprotected obviously) it disappears and then my save macro
doesn't work because it can't find the designated formfield. (The reset
fields button doesn't do anything either) I can't figure out how to prevent
this.

What's my best option. I'd like the form to be protected ideally, so the
users can't change the formatting of the document, just enter their
information and then save it.

Thanks
Jeremy
 
J

Jeremy

Ok, sorry....

Stupid rookie mistake. In the formfield properties window I didn't have the
"Fill-in Enabled" box checked. So...now I do that and protect my form, and
of course everything is working just great.

Now...I've discovered a new problem. It just never ends, I know. When I'm
making a new document using my template, I can fill in all my fields
properly but then when I try to click on my button, it doesn't let me and it
just jumps back to the first field. My button looks like this:

{Macrobutton macroname Double Click to Save}

And of course I just put a drawing box around it to make it look more like a
button instead of just text. I've tried doing it with a picture instead of
text but the same thing happens. So...now what? It's like the protected
template is not letting people run the macro or something, how can I allow
this?

Thanks again,
Jeremy
 
J

Jay Freedman

Macrobutton fields *do* work in a protected form. Make sure that:

- The second word in the field code (macroname) is spelled *exactly*
like the actual name of the macro -- although it isn't case-sensitive,
you do have to get everything else about the name exactly right. It's
best to copy the name from the VBA editor and paste into the field
code.

- You double-click instead of single-click. That also implies you do
it quickly enough that Windows recognizes it as a double-click. The
alternative is to include this statement in the form's AutoOpen() and
AutoNew() procedures:

Options.ButtonFieldClicks = 1

Then you can change the field display phrase to just "Click to save".

- The macro actually does what you think it should. It's possible that
the macro does run but exits without doing anything, possibly because
an On Error trap is being triggered. For testing purposes, temporarily
insert a MsgBox statement at the start of the macro, or set a
breakpoint on an existing statement.
 

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