简体   繁体   中英

Automatically folder open after save excel vba

below is my code for the file to be saved to specific folder. my question is how can I make the folder of the location is open automatically after save complete. I google about "aftersave event" but nothing come out .

Private Sub savebr_Click()

Dim saveas As String
saveas = "C:\user\file"
Application.Dialogs(xlDialogSaveAs).Show saveas

End Sub

So you want to open the folder where the current workbook was saved automatically after saving. Paste this code in the ThisWorkbook code in the VB Editor

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    Call Shell("explorer.exe" & " " & ThisWorkbook.Path, vbNormalFocus)
End Sub

屏幕截图

Thisworkbook.path open every time same workbook path(ie your macro file path)

If your are adding many excel workbooks and save it on different path and want to open this path so you should use below code.

Not necessary to use event for this, you can simply write code after saving workbook.

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    Call Shell("explorer.exe" & " " & Activeworkbook.Path, vbNormalFocus)
End sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM