Ken0815
Ken0815

Reputation: 3

How to make SaveAs in its original path folder instead of "My document"

So basically I got this working with the code below to save a file with date as name by default.

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

However the path is set to SaveAs at "My Document" how do i change it to be saved in the document original path , something like...

XXXX = Options.DefaultFilePath(wdStartupPath)

Upvotes: 0

Views: 163

Answers (1)

Mikku
Mikku

Reputation: 6654

This will work:

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

I have used Activedocument.Path property to find the current path.

Upvotes: 1

Related Questions