The easiest thing is to use a text formfield into which the user will enter
the invoice number. If however, you do not want/cannot tolerate the
document being protected for forms, you can get away with using a bookmark
IF, when creating the bookmark, the selection includes a space both before
and after the [Click Here] so that with the display of bookmarks turned on,
you see
[ [Click Here] ]
where the outer [ ] are the bookmark markers.
The you can use
Dim Invoice as String
Invoice = Trim(ActiveDocument.Bookmarks("bookmarkname").Range.Text
If you do not have the spaces before and after, when the user enters the
invoice number, the bookmark will be deleted from the document and the code
will not work.
The snippet of someone else's code that you posted was created for the use
of a formfield in a protected document, though it is probably better to use:
ActiveDocument.FormFields("ProjectName").Result
Note, you do not have to show the FileSaveAs dialog if you do not want the
user to have the ability to change the path or filename. Just use the
ActiveDocument.SaveAs command, supplying the necessary path and filename to
it, such as
ActiveDocument.SaveAs "c:\Invoices\" & Invoice
Where Invoice is declared and populated as first mentioned above.
For more on forms, see:
Please Fill Out This Form
Part 1: Create professional looking forms in Word
http://www.computorcompanion.com/LPMArticle.asp?ID=22
Part 2: Adding Automation to your Word forms.
http://www.computorcompanion.com/LPMArticle.asp?ID=46
Part 3: Learn more VBA (macros) to automate your forms.
http://www.computorcompanion.com/LPMArticle.asp?ID=119
Part 4: Use custom dialog boxes in your Word forms
http://www.computorcompanion.com/LPMArticle.asp?ID=127
Part 5: Connect your AutoForm to a database to save input time and keep
better records!
http://www.computorcompanion.com/LPMArticle.asp?ID=136

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Looks like this:
>
[quoted text clipped - 38 lines]
>
> End Sub
Jeremy - 05 Jun 2005 21:34 GMT
Ok...the saga continues....
Eventually I'm going to be a pro at all this programming stuff.
Anyways....I've created a macro that automatically saves the current file to
a specified directory without displaying the saveas dialog box because I do
not want the user to have the option of changing the field....and it works
great.
Now I've gone one step further and created a custom dialog box that pops up
when this save macro has been activated and it basically confirms that they
have saved their file. I'm trying to use two command buttons on my form.
I've got one working that is just an "OK" button...that basically just hides
the form and returns to the document when clicked. The second one that I'm
trying to use is a command button that will close down MS Word and return to
windows desktop. I can't seem to figure out the code. I found one but it
actually closes down all programs including windows.
Any suggestions?
Now...my original problem also still exists....I've been playing with text
boxes and bookmarks and I'm yet to figure out how to make a field of some
kind that automatically enters itself as the filename when I run the save
macro.
> The easiest thing is to use a text formfield into which the user will
> enter the invoice number. If however, you do not want/cannot tolerate the
[quoted text clipped - 93 lines]
>>
>> End Sub
Jeremy - 05 Jun 2005 21:57 GMT
And to clarify....my save macro looks like this:
Sub save()
'
' save Macro
' Macro created 6/5/2005 by Jeremy
'
ActiveDocument.SaveAs "C:\Jer-Pictures\My Pictures\motorcycles"
UserForm1.Show
End Sub
So....I'm having difficulty understanding how to edit the save as line to
include the name with the path. I've got a text input form field on my
page called invoice and I've created a bookmark around it also called
invoice. So what do I need to add to this save macro to grab the info from
the invoice field, and use that as the filename. (Users will obviously be
punching in a invoice number into this field and I want the file to
automatically save as the invoice number.)
Thanks.