VBA 另存为文件路径

VBA save as Filepath

我正在尝试使用此处找到的代码:

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

我想将任何打开的 word 文档保存到特定的文件夹路径,我该如何更改

文件名:=aDoc.FullName

到特定位置,例如C:\Users\joe.blog\Desktop\Backup

使用FullName 属性包含原始路径。

您需要使用 Name 属性 提取文件名并将其附加到您的路径

像这样

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