「VBA」修訂間的差異

出自ProgWiki
跳至導覽 跳至搜尋
行 4: 行 4:
 
*[https://docs.microsoft.com/zh-tw/office/vba/api/overview/ Office VBA 參考]
 
*[https://docs.microsoft.com/zh-tw/office/vba/api/overview/ Office VBA 參考]
 
**[https://docs.microsoft.com/zh-tw/office/vba/language/reference/functions-visual-basic-for-applications 函數]
 
**[https://docs.microsoft.com/zh-tw/office/vba/language/reference/functions-visual-basic-for-applications 函數]
 +
 +
==FAQ==
 +
===取得資料夾路徑===
 +
*原始出處: [https://stackoverflow.com/questions/28054713/folder-picker-for-ms-word Folder Picker for MS Word]
 +
<source lang="vb">
 +
Function GetFolder(strPath As String) As String
 +
    Dim fldr As FileDialog
 +
    Dim sItem As String
 +
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
 +
    With fldr
 +
        .Title = "Select a Folder"
 +
        .AllowMultiSelect = False
 +
        .InitialFileName = strPath
 +
        If .Show <> -1 Then GoTo NextCode
 +
        sItem = .SelectedItems(1)
 +
    End With
 +
NextCode:
 +
    GetFolder = sItem
 +
    Set fldr = Nothing
 +
End Function
 +
</source>
  
 
[[分類:Microsoft Office]]
 
[[分類:Microsoft Office]]
 
[[分類:Script語言]]
 
[[分類:Script語言]]

於 2019年7月4日 (四) 22:12 的修訂

VBA(Visual Basic for Applications),參照:『維基百科~Visual_Basic_for_Applications

參考資料

FAQ

取得資料夾路徑

Function GetFolder(strPath As String) As String
    Dim fldr As FileDialog
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    With fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = strPath
        If .Show <> -1 Then GoTo NextCode
        sItem = .SelectedItems(1)
    End With
NextCode:
    GetFolder = sItem
    Set fldr = Nothing
End Function