Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

VBA 呼叫資料夾選擇對話框的三種方式

VBA 呼叫資料夾選擇對話框有三種常見方式:API、Shell.Application、FileDialog。

Shell.Application

Sub GetFolder_Shell()
    Dim objShell As Object
    Set objShell = CreateObject("Shell.Application")
    Dim objFolder As Object
    Set objFolder = objShell.BrowseForFolder(0, "選擇文件夾", 0, 0)
    If Not objFolder Is Nothing Then MsgBox objFolder.self.path
End Sub

FileDialog

Sub GetFolder_FileDialog()
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    If fd.Show = -1 Then MsgBox fd.SelectedItems(1)
End Sub

API 方式較複雜,但相容性佳;FileDialog 簡潔,適合 Office 環境。

Copyright © Linux教程網 All Rights Reserved