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:
    269
    Likes Received:
    21
    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

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.
Similar Threads
  1. korgan99
    Replies:
    0
    Views:
    1,261
    korgan99
    Dec 20, 2011
  2. lb_duck
    Replies:
    0
    Views:
    1,154
    lb_duck
    Feb 28, 2012
  3. TFinnis
    Replies:
    1
    Views:
    638
    macropod
    Jun 13, 2012
  4. tom12
    Replies:
    0
    Views:
    840
    tom12
    Aug 13, 2012
  5. htmldiva

    Word Header Macro Problem

    htmldiva, Aug 26, 2012, in forum: Word
    Replies:
    0
    Views:
    718
    htmldiva
    Aug 26, 2012
  6. rv.aleixo.alves

    Macro for insert oval shape in table cell

    rv.aleixo.alves, Apr 18, 2013, in forum: Word
    Replies:
    1
    Views:
    747
    rv.aleixo.alves
    Apr 20, 2013
  7. bennymc
    Replies:
    0
    Views:
    287
    bennymc
    Jan 29, 2014
  8. Rajan Kandola
    Replies:
    0
    Views:
    1,043
    Rajan Kandola
    May 6, 2014
Loading...