SamuelBazniar
SamuelBazniar

Reputation: 21

Get the saved file name in VBA for Word

I need your help to unlock me.

I would like to retrieve the name of the file saved by the user with Word in VBA. I'm using the BeforeSave method, but I can not seem to catch the name chosen by the user.

Thank you in advance for your help !

Upvotes: 1

Views: 260

Answers (1)

Dave Thunes
Dave Thunes

Reputation: 280

With the save as pane not triggering the SaveAs() sub, I think the only reliable way to do this is an OnTime event triggered by DocumentBeforeSave.

Something like:

Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    If SaveAsUI = True Then
        Word.Application.OnTime Now + TimeValue("00:00:01"), "AfterSave"
    Else
        DoStuff()
    End if
End Sub
Sub AfterSave()
    CheckSaveOccured()
    DoStuff()
End Sub

See this post for a more detailed explanation.

Upvotes: 1

Related Questions