Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: save as macro

  1. #1
    klott01
    Guest

    save as macro

    Does anyone have a macro for "save as"? Have created a form in Word, and want the document save as name to be what I have entered into a certain field.

  2. #2
    klott01
    Guest

    Re: save as macro

    Ok, thanks...basically--
    Text form field has label "project name". Whatever is entered into that field should become the "save as" file
    name. For example, if I enter "Order Entry" into that field in that form, the document should save as "order entry.doc--and if possible, would like to designate the drive and directory.

    thx

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: save as macro

    Do you want the dialog to show with the suggested name? If that's the case:
    <pre>Sub FileSaveAs()
    With Dialogs(wdDialogFileSaveAs)
    .Name = "SomeName"
    .Show
    End With
    End Sub
    </pre>


    Otherwise just:
    Sub FileSaveAs()
    ActiveDocument.SaveAs FileName:="c:directoryyourname"

    End Sub
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: save as macro

    Kathy,

    Do you mean you would like to designate the drive and directory, or you want the user to designate?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    klott01
    Guest

    Re: save as macro

    I would like to designate it if possible. We want all of these forms saved to a certain directory on our network drive.

  6. #6
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: save as macro

    I think this will do what you want- where sFilename is a string containing the file name:


    ActiveDocument.SaveAs FileName:="h:directory" & sFileName

    If you want to save it automatically, include that line at the end of the macro. If you want it to save when the user selects "File, Save As" put it into a routine: "Sub FileSaveAs"- similalrly to put it into "FileSave"
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  7. #7
    klott01
    Guest

    Re: save as macro

    Thanks! We are going to give it a shot, and will let you know!

  8. #8
    klott01
    Guest

    Re: save as macro

    gwhitfield,
    Hi, my name is JimK, I am working with Klott on this project. This macro works but creates a file with only the extention ".doc", the filename part is blank. I am trying to populate the filename part with data that was just keyed into the form field, then when I exit that form field it saves to a filename using the data in that field. The properties for that form field state that it is bookmark Text3. Is this also a reference to the form field variable? Here is the macro that is set to activate when leaving form field Text3:

    Sub FileSaveAs()
    '
    ' FileSaveAs Macro
    ' Saves a copy of the document in a separate file
    '

    ActiveDocument.SaveAs FileName:="//bdc/operations/Staff Support/" & sText3
    End Sub

    Any help would be appreciated.
    Thanks

  9. #9
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: save as macro

    Hi Jim,

    If it's attached to a form field, then call it something different to "FileSaveAs"- which is a macro which executes when someone clicks "File, Save As".

    So you might have something like:

    sub SaveTheDoc
    ActiveDocument.SaveAs FileName:="//bdc/operations/Staff Support/" & Activedocument.FormFields("Text3").Result & ".doc"
    end sub


    Presumably you've been able to link the macro to execute when you've exited the macro- but just in case- double click on the form field, select "run macro on, Exit" and enter "SaveTheDoc" (it should be shown in a drop down list).

    Are we getting closer yet?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  10. #10
    klott01
    Guest

    Re: save as macro

    gwhitfield,
    Hit, it's JimK again... You are awesome, that works great!!! However, If the user enters nothing into the field, or just tries to tab through it, the macro save a file called ".doc" (no filename, just an extention)... Is there anyway to check to see if the field is blank, if so kick out a error message?

  11. #11
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: save as macro

    Hi Jim,

    I haven't tried this out, but something like the following ought to work:

    sub SaveTheDoc
    If ActiveDocument.FormFields("Text3").Result = "" Then
    MsgBox "Please enter a value for this field"
    Exit Sub
    Else
    ActiveDocument.SaveAs FileName:="//bdc/operations/Staff Support/" & Activedocument.FormFields("Text3").Result & ".doc"
    End If
    end sub

    Gary

  12. #12
    klott01
    Guest

    Re: save as macro

    Gary,
    JimK here again. I can not that you enough for all your help!!! That works great, but now after the macro displays the error message the cursor jumps to the next field. How do you stuff a BackTab at the macro to get the cursor to tab back to the previous field? This should cause an infinite loop while the field is unpopulated and that is fine.

  13. #13
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: save as macro

    After the Msgbox, put in the line:

    ActiveDocument.FormFields("Text3").Select
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  14. #14
    klott01
    Guest

    Re: save as macro

    gary,
    Well, rats, that didn't work... it still jump to next field... hmmm... here is the code:

    Sub SaveTheDoc()
    If ActiveDocument.FormFields("Text3").Result = "" Then
    MsgBox "Please enter a Project Name"
    SubActiveDocument.FormFields("Text3").Select
    Exit
    Else
    ActiveDocument.SaveAs FileName:="//bdc/operations/Staff Support/" & ActiveDocument.FormFields("Text3").Result & ".doc"
    End If
    End Sub

    Thanks for all your help,
    JimK

  15. #15
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: save as macro

    Jim (logged on as Kathy I assume)

    (This is Geoff not Gary)
    This will work when tabbing forward- NOT when tabbing back:

    Sub SaveTheDoc()
    If ActiveDocument.FormFields("Text3").Result = "" Then
    MsgBox "Please enter a Project Name"
    SendKeys "+{tab}"
    Else
    ActiveDocument.SaveAs FileName:="//bdc/operations/Staff Support/" & ActiveDocument.FormFields("Text3").Result & ".doc"
    End If
    End Sub
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Page 1 of 2 12 LastLast

Posting Permissions

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