Home > other >  VBA save as Filepath
VBA save as Filepath

Time:03-25

I'm attempting to use this code found here:

https://answers.microsoft.com/en-us/msoffice/forum/all/can-i-save-as-multiple-documents-at-one-time/eae10efb-1984-4131-b072-a96d45020ba9

Sub SaveAllOpenDocsAsDocx()

For Each aDoc In Application.Documents

    aDoc.SaveAs FileName:=aDoc.FullName & ".doc", FileFormat:=wdFormatDocument

    aDoc.Close

Next aDoc

End Sub

I'd like to save any open word documents to a specific folder path, how would I go about changing

FileName:=aDoc.FullName

to a specific locations e.g. C:\Users\joe.blog\Desktop\Backup

CodePudding user response:

Using FullName property includes the original path.

You need to pull out the Filename and append that to your path

Something like this

Sub SaveAllOpenDocsAsDocx()
    Const MY_LOCATION = "C:\Users\joe.blog\Desktop\Backup\"
    Dim myFileLocation As String

    For Each aDoc In Application.Documents
        myFileLocation = MY_LOCATION & aDoc.Name & ".doc"
        aDoc.SaveAs FileName:=myFileLocation, FileFormat:=wdFormatDocument
        aDoc.Close
    Next aDoc

End Sub
  • Related