Having word save my files with names from my text

P

Phil J W

Hi,

I've created a form in word 2007 and i'd like the file to take the text from
the form for a file name isntead of the first line of ttext in the document.

Is this possible?

Thanks Phil
 
G

Graham Mayor

Assuming legacy form fields and you want the name from the field named
"Text1" the following macro saved in the form template should work

Sub FileSave()
Dim sPath As String
sPath = Options.DefaultFilePath(wdDocumentsPath) 'set the path
sPath = sPath & "\"
With ActiveDocument
If .FormFields("Text1").Result <> "" Then
.SaveAs sPath & .FormFields("Text1").Result & ".docx", _
wdFormatDocumentDefault
Else
MsgBox "You must complete formfield Text1", vbCritical, "Error"
.FormFields("Text1").Select
End If
End With
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Phil J W

I'm actaully using a Rich Text Content control...does that affect the code?
You would think microsoft would have created this in word as a feature....
 
G

Graham Mayor

The code will not work with rich text controls. The rich text controls in
2007 are at a somewhat primitive state of development. Better to use legacy
fields if you want more control. To aid that see
http://gregmaxey.mvps.org/Classic Form Controls.htm , You may also find
more information about content controls on Greg's web site.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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