Share via

macro help save-as to same folder as current file

Anonymous
2018-02-12T22:49:18+00:00

I have the follow macro below which works great to pull info already in the document for the file name so it creates a standard filename format for each document without having to type the file name each time when saved.

Right now it defaults to save the PDF being created from the word .docx file to default file folder setup in word. I would like this to be the current folder that the .docx file is already saved to, not the main folder if that makes sense? Can anyone suggest how to modify the macro to achieve this? Not very good with code.

Thanks,

Sub savedefreport()

'

' savedefreport Macro

'

'

Dim strADDRESS As String, strDATE As String

Dim FD As FileDialog

Dim strFolder As String

Dim strFilename As String

strADDRESS = ActiveDocument.SelectContentControlsByTitle("ADDRESS")(1).Range.Text

strDATE = ActiveDocument.SelectContentControlsByTitle("DATE")(1).Range.Text

strFilename = "" & Deficiency & " " & Report & "" & strADDRESS & " " & Format(strDATE, "MMM d, yyyy") & ".pdf"

ActiveDocument.ExportAsFixedFormat OutputFileName:="Deficiency Report" & strFilename, _

                                   ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _

                                   wdExportOptimizeForPrint, Range:=wdExportFromTo, From:=2, To:=2, _

                                   Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _

                                   CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _

                                   BitmapMissingFonts:=True, UseISO19005_1:=False

End Sub

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2018-02-12T23:18:22+00:00

The active documents path can be stored with the following

StrFolder = activedocument.Path & application.PathSeparator

Hope this helps

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful