save as macro based on a form field

B

baiju

i have a protected form to fill data.i want to automate the save as with a
macro.after finished entering the data when i run the macro it should save
the file in a specified directory as a word document with name as the data
from the field 1. can it be done?

i am very very new to vb,appreciate your detailed help.
thanks again;
baiju
 
D

Doug Robbins - Word MVP

Run a macro on exit from the last formfield that contains the code

With ActiveDocument
.SaveAs "C:\foldername\" & .FormFields("Bookmarknameofformfield").Result
End With

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
G

Graham Mayor

While Doug has provided the method, it would probably be worth adding some
error correction to ensure that there is content in the field being used to
name the document - something along the lines of

With ActiveDocument
If Len(.FormFields("Bookmarknameofformfield").Result) = 0 Then
MsgBox "This field must be completed", vbCritical, "Empty field"
.FormFields("Bookmarknameofformfield").Select
Else
.SaveAs "C:\foldername\" &
..FormFields("Bookmarknameofformfield").Result
End If
End With


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

baiju

Hi;
extremely thankfull to you both for your reply.i tried as doug suggested but
it showed a compile error. it could be due to my ignorance in vba.Appreciate
if one of you could make athe full code which i need to put in the vba editor
with following paramaters
folder---C:\dictation
bookmarkname of form field---Text13
thanks once again for your kind help
baiju
 
D

Doug Robbins - Word MVP

Sub SaveDoc()
With ActiveDocument
If Len(.FormFields("Text13").Result) = 0 Then
MsgBox "This field must be completed", vbCritical, "Empty field"
.FormFields("Text13").Select
Else
.SaveAs "C:\dictation\" & .FormFields("Text13").Result
End If
End With
End Sub

should do it if you set the macro SaveDoc to run on exit from the Text13
formfield. I would suggest however that you give the formfields names that
have some meaning rather than just use the default bookmark name.

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 

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