Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Document Management / May 2008

Tip: Looking for answers? Try searching our database.

Form Field and Save As

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ArcticWolf - 03 Jan 2008 16:21 GMT
Hi,

I have a Word doc with a form field (user ID) in which the user enters their
unique user ID.  Can I automate Word so when the user exits the document it
automatically saves the file name as their user ID?
IE - my unique ID is 12345 so the file name will need to be 12345.doc

Thanks in advance

AW
Graham Mayor - 04 Jan 2008 07:51 GMT
This can be achieved with a simple macro saved in the form template and run
preferably on exit from the UserID form field

Sub SaveForm()
Dim fName As String
fName = ActiveDocument.FormFields("UserID").Result & ".doc"
ActiveDocument.SaveAs fName
End Sub

This will automatically name the document as required. The user will get a
prompt to save the document if it is closed without saving.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi,
>
[quoted text clipped - 7 lines]
>
> AW
tmirelle - 20 Mar 2008 20:49 GMT
Is it possible to do this with data from two fields?

ie last name & first name?

so result would be lastfirst.doc

> This can be achieved with a simple macro saved in the form template and run
> preferably on exit from the UserID form field
[quoted text clipped - 19 lines]
> >
> > AW
Graham Mayor - 21 Mar 2008 09:10 GMT
Yes you can do it with the data from two fields.where firstname and lastname
are the names of the associated form fields.

Sub SaveForm()
Dim fName As String
With Active Document
   fName = .FormFields("LastName").Result
   fName = fName & .FormFields("FirstName").Result & ".doc"
   .SaveAs fName
End With
End Sub

Run on exit from whichever field is completed second of the two fields (or
from a later field)

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Is it possible to do this with data from two fields?
>
[quoted text clipped - 34 lines]
>>>
>>> AW
tmirelle - 20 Mar 2008 20:50 GMT
Oh, & how do I make it run on exit of the field?

Many many thnaks

> This can be achieved with a simple macro saved in the form template and run
> preferably on exit from the UserID form field
[quoted text clipped - 19 lines]
> >
> > AW
Graham Mayor - 21 Mar 2008 09:12 GMT
Double click the field with the form unlocked and assign it to the Run Macro
on Exit property.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Oh, & how do I make it run on exit of the field?
>
[quoted text clipped - 32 lines]
>>>
>>> AW
tmirelle - 23 Mar 2008 18:32 GMT
This is amazing! thanks!!

...can you force where the document should save? e.g the desktop?

& probably no way to avoid having pop up warning about the macro, right?

> Double click the field with the form unlocked and assign it to the Run Macro
> on Exit property.
[quoted text clipped - 35 lines]
> >>>
> >>> AW
Graham Mayor - 24 Mar 2008 06:58 GMT
You can add a path to the filename and it will save to it. The macro warning
is always going to be an issue if you save the macros in a document. Save
the document as a template and create new documents from it.

Sub SaveForm()
Dim fName As String
With ActiveDocument
   fName = .FormFields("LastName").Result
   fName = fName & .FormFields("FirstName").Result & ".doc"
   .SaveAs "C:\Path\" & fName
End With
End Sub

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> This is amazing! thanks!!
>
[quoted text clipped - 51 lines]
>>>>>
>>>>> AW
jatman - 14 May 2008 07:24 GMT
i am trying to adapt the below code for Word 2007.  i have tried the
following but to no success.

changed the .doc to .docx (office 2007 standard for saving) but when i run
the macro, i get an error and the fname line is highlighted yellow, when i go
to the line, it shows fname=""

i changed the .FormFields to .Bookmarks, then i get an erro also, but the
.Result is highlighted.

i have reviewed other sources, but the macro that is listed here is more or
less what i am looking for - simple.  

any other suggestions on this is appreciated.

jat

> This can be achieved with a simple macro saved in the form template and run
> preferably on exit from the UserID form field
[quoted text clipped - 19 lines]
> >
> > AW
Graham Mayor - 14 May 2008 12:11 GMT
The macro works with Word 2007, assuming of course that there is content in
the UserID (legacy field) text field. The following will error trap no
content:

Sub SaveForm()
Dim fName As String
On Error GoTo Noname
With ActiveDocument
   fName = .FormFields("UserID").Result & ".docx"
   .SaveAs fName, FileFormat:=wdFormatDocumentDefault
End With
Exit Sub
Noname:
MsgBox "UserID field is empty"
End Sub

If you want to use the content of a bookmark then

Sub SaveForm()
Dim fName As String
On Error GoTo Noname
With ActiveDocument
   fName = .Bookmarks("UserID").Range.Text & ".docx"
   .SaveAs fName, FileFormat:=wdFormatDocumentDefault
End With
Exit Sub
Noname:
MsgBox "UserID bookmark is empty"
End Sub

or you could use the built-in document properties

Sub SaveForm()
Dim fName As String
On Error GoTo Noname
With ActiveDocument
   fName = ActiveDocument.BuiltInDocumentProperties("Author") & ".docx"
   .SaveAs fName, FileFormat:=wdFormatDocumentDefault
End With
Exit Sub
Noname:
MsgBox "Author field is empty"
End Sub

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> i am trying to adapt the below code for Word 2007.  i have tried the
> following but to no success.
[quoted text clipped - 45 lines]
>>>
>>> AW
jatman - 14 May 2008 18:08 GMT
the first two did not work (form fields and bookmarks,) probably on how i am
setting up the fields or something.  so i tried the last one using the built
in document properties thinking it would not work that way i was hoping, and
it worked like a charm.  from here, it should be a breeze.

thank you!

> The macro works with Word 2007, assuming of course that there is content in
> the UserID (legacy field) text field. The following will error trap no
[quoted text clipped - 89 lines]
> >>>
> >>> AW
jatman - 15 May 2008 06:59 GMT
thought i was doing well, but one more question.

how do i join two built in document properties?  i am using the Publish Date
and Title.  i tried the following:

With ActiveDocument
   fName = activedocument.builtindocumentproperties("Publish Date")
    fName = fname & " " & ActiveDocument.BuiltInDocumentProperties("Title")
& ".docx"
    .SaveAs fName, FileFormat:=wdFormatDocumentDefault

i am not sure, but i think it has to do with the date.  when i use the Title
alone, it worked.  i added the date line to it and now i'm stuck.  so i tried
the publish date alone and i get the "empty field error"

the Publish Date uses the date picker, properties display it as dddd,
mmmm-dd-yyyy, and it stores XML contents as Text (same as display.)  i tried
the store as date also and no luck.

i really do not care as to how it shows, but the file should save as
"yyyy-mm-dd title of document"

thank you for your assistance so far!

jat

> The macro works with Word 2007, assuming of course that there is content in
> the UserID (legacy field) text field. The following will error trap no
[quoted text clipped - 89 lines]
> >>>
> >>> AW
Graham Mayor - 15 May 2008 08:10 GMT
There is no 'built-in document property' called "Publish Date"
You could use the current date eg

With ActiveDocument
   fName = Format(Date, "d" & _
       Chr(32) & "MMMM" & Chr(32) & "yyyy") & _
       .BuiltInDocumentProperties("Title") & ".docx"
    .SaveAs fName, FileFormat:=wdFormatDocumentDefault
End With

or you could create and use a custom document property called Publish Date
then

With ActiveDocument
   fName = .CustomDocumentProperties("Publish Date") & _
       .BuiltInDocumentProperties("Title") & ".docx"
    .SaveAs fName, FileFormat:=wdFormatDocumentDefault
End With

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> thought i was doing well, but one more question.
>
[quoted text clipped - 125 lines]
>>>>>
>>>>> AW
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.