简体   繁体   English

保存excel vba后自动打开文件夹

[英]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 将此代码粘贴到VB编辑器的ThisWorkbook代码中

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) 每当打开相同的工作簿路径(即您的宏文件路径)时,都会打开thisworkbook.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. 如果您要添加许多excel工作簿并将其保存在其他路径上,并想打开此路径,则应使用以下代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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