如何在其原始路径文件夹而不是“我的文档”中创建SaveAs

时间:2019-05-30 06:13:44

标签: vba ms-word

因此,基本上,我可以使用下面的代码来保存默认情况下以日期为名称的文件。

Sub 巨集8()
'
    Dim xDlg As Dialog
    Dim xTitle As String
    On Error Resume Next
    xTitle = ActiveDocument.BuiltInDocumentProperties("Title").Value
    xTitle = xTitle & "- " & Format((Year(Now() + 1) Mod 100), "20##") & "" & _
        Format((Month(Now() + 1) Mod 100), "0#") & "" & _
        Format((Day(Now()) Mod 100), "0#")
    Set xDlg = Dialogs(wdDialogFileSaveAs)
    xDlg.Name = xTitle
    xDlg.Show
End Sub

但是,在“我的文档”中将该路径设置为SaveAs时,如何更改它以保存在文档原始路径中,例如...

XXXX = Options.DefaultFilePath(wdStartupPath)

1 个答案:

答案 0 :(得分:0)

这将起作用:

Sub 巨集8()

Dim xDlg As Dialog
Dim xTitle As String
On Error Resume Next
xTitle = ActiveDocument.BuiltinDocumentProperties("Title").Value
xTitle = xTitle & "- " & Format((Year(Now() + 1) Mod 100), "20##") & "" & _
    Format((Month(Now() + 1) Mod 100), "0#") & "" & _
    Format((Day(Now()) Mod 100), "0#")
Set xDlg = Dialogs(wdDialogFileSaveAs)
xDlg.Name = ActiveDocument.Path & "\" & xTitle
xDlg.Show

End Sub

我已经使用Activedocument.Path属性来找到当前路径。