Having word save my files with names from my text

  • Thread starter Thread starter Phil J W
  • Start date Start date
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
 
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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
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....
 
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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top