saveas macro help

Joined
Oct 8, 2016
Messages
1
Reaction score
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
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
580
Reaction score
50
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top