PDA

View Full Version : Solved: Text Form Field



mgonzalez07
08-19-2005, 07:26 PM
Hi, I'm new to VBA and to this forum and I could really use your help. I am trying to write a macro that will save a file as whatever is written in a Text Form Field. This is what I have so far but it seems that the file is always saved as "FORMTEXT name" I can not get rid of "FORMTEXT" Does anyone have any ideas?

Sub Save()

strVar = ActiveDocument.Bookmarks("Text9").Range

ActiveDocument.SaveAs FileName:=strVar, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False

End Sub

Jacob Hilderbrand
08-19-2005, 07:35 PM
How about this?


strvar = Replace(ActiveDocument.Bookmarks("Text9").Range, "FORMTEXT ", "")

mgonzalez07
08-19-2005, 07:55 PM
It works just like I wanted it to. Thanks DRJ

Jacob Hilderbrand
08-19-2005, 08:38 PM
You're Welcome :beerchug:

Take Care

fumei
08-20-2005, 02:18 AM
Uh.....

FormFields are also bookmarks - t'is true. However, they are formfields, and they have values.

Instead of:
strVar = ActiveDocument.Bookmarks("Text9").Range, or doing any replacing;

use:
strVar = ActiveDocument.Formfields("Text9").Result

Result gives the value of the formfield directly. Using the Bookmark collection item, and the .Range.Text will return the bookmark field text.