saveas macro help

Discussion in 'Word' started by higguns, Oct 9, 2016.

  1. higguns

    higguns

    Joined:
    Oct 8, 2016
    Messages:
    1
    Likes Received:
    0
    hello,

    I have created with the help of searching and research a macro which will pull info inputted in the file (which is an invoice) such as address, date, and invoice number from Content control forms.

    After much trial and error I have the macro working, however not to a T yet.

    It is supposed to pop up a save as dialog and ask where the file should be saved. It does this, however it also saves it to the first location that is opened (or last opened location).

    I tried removing and re-arranging the last statements of the macro without any luck. All I want it to do is pull the info to automatically create the file name and then ask where it should be saved (so it can be put in the corresponding folder and keep things organized).

    Here's the script I have and the lines in RED are the ones that I believe need changing. Please help

    Sub saveasinvnumnamedate()
    '
    ' saveasinvnumnamedate Macro
    '
    '
    Dim strINVNUM As String, strADDRESS As String, strDATE As String

    strINVNUM = ActiveDocument.SelectContentControlsByTitle("INVNUM")(1).Range.Text
    strADDRESS = ActiveDocument.SelectContentControlsByTitle("ADDRESS")(1).Range.Text
    strDATE = ActiveDocument.SelectContentControlsByTitle("DATE")(1).Range.Text

    Dim strFilename As String
    strFilename = "INVOICE" & " " & strINVNUM & " " & strADDRESS & " " & Format(strDATE, "MMM d, yyyy") & ".docx"

    ActiveDocument.SaveAs strFilename
    Dialogs(wdDialogFileSaveAs).Show



    End Sub
     
    higguns, Oct 9, 2016
    #1
    1. Advertisements

  2. higguns

    macropod Microsoft MVP

    Joined:
    Mar 2, 2012
    Messages:
    336
    Likes Received:
    29
    Try:

    Sub SaveAsInvNumNameDate()
    Dim strFilename As String
    With ActiveDocument
    strFilename = .SelectContentControlsByTitle("INVNUM")(1).Range.Text
    strFilename = strFilename & " " & .SelectContentControlsByTitle("ADDRESS")(1).Range.Text
    strFilename = strFilename & " " & .SelectContentControlsByTitle("DATE")(1).Range.Text
    strFilename = strFilename & " " & Format(strDATE, "MMM d, yyyy") & ".docx"
    With Dialogs(wdDialogFileSaveAs)
    .Name = strFilename
    .Show
    End With
    End With
    End Sub
     
    macropod, Oct 17, 2016
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.