Consulting

Results 1 to 5 of 5

Thread: Solved: Text Form Field

  1. #1

    Solved: Text Form Field

    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?

    [VBA] 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
    [/VBA]

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    How about this?

    [vba]
    strvar = Replace(ActiveDocument.Bookmarks("Text9").Range, "FORMTEXT ", "")[/vba]

  3. #3

    It works great!

    It works just like I wanted it to. Thanks DRJ

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •