Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Ephrata, Washington, USA
    Posts
    683
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Save as pulls name from field (2003)

    Someone asked me if he can save new documents with names pulled from fields. He needs to create a ton of forms and for each one he types a form number form field near the top of the document (but not the first line of the document). What he wants to do is type the form number in the field, fill out the field, press Save and Word will "Save as" and pull the form number from that form field. You know ... sorta like when you create a new document and press save it puts the first few words in the name field on the save as dialog box. But this time, he wants it to pull the name from the field he has created so he doesn't have to remember to type the name. He is very good with VBA, and is willing to use that if necessary.

  2. #2
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save as pulls name from field (2003)

    <hr>If InStr(ActiveDocument.FullName, "") < 0 Then<hr>
    Hi Hans,

    Found this interesting and tested it, but this condition seemes never to be True. Shouldn't that be < 1 instead ?

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Save as pulls name from field (2003)

    It's a typo allright. It should have been > 0 instead of < 0. If the document has been saved to disk, there must be a backslash in the full name, hence InStr will return a positive value (the position of the first backslash). If the document hasn't been saved yet, there will be no backslash in the full name, hence InStr will return 0.

    I will correct my original reply. Thanks for pointing out the error!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Save as pulls name from field (2003)

    Edited to correct typo: changed < to >. Thanks to JanB for pointing out the mistake.

    He can create macros named FileSave and FileSaveAs in the documents or templates. These will overrule the built-in commands.

    Sub FileSaveAs()
    With Dialogs(wdDialogFileSaveAs)
    .Name = ActiveDocument.FormFields("Text1").Result
    .Show
    End With
    End Sub

    Sub FileSave()
    ' Test if document has been saved on disk
    If InStr(ActiveDocument.FullName, "") > 0 Then
    ActiveDocument.Save
    Else
    FileSaveAs
    End With
    End Sub

  5. #5
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save as pulls name from field (2003)

    Yeah... by making another error myself... <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

Posting Permissions

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