VBA - User-defined type not defined

后端 未结 1 709
醉梦人生
醉梦人生 2021-01-15 03:12

I am trying to update an VBA module to use the System.Windows.Forms.FolderBrowserDialog class. I declared my object as follows:

Dim MyFolderBrow         


        
相关标签:
1条回答
  • 2021-01-15 03:58

    System.Windows.Forms.FolderBrowserDialog looks like something from .Net to me, not VBA.

    You can use Application.FileDialog in Access VBA. This sample uses late binding and allows the user to select a folder from a browse dialog.

    Const msoFileDialogFolderPicker As Long = 4
    Dim objFileDialog As Object ' FileDialog
    Set objFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    
    With objFileDialog 
        .AllowMultiSelect = False
        If .Show Then
            Debug.Print .SelectedItems(1)
        End If
    End With
    

    If you prefer to use early binding, set a reference to the Microsoft Office [version] Object Library. You could then declare the object like this ...

    Dim objFileDialog As FileDialog
    

    And you wouldn't need to define the constant, so discard this line if using early binding ...

    Const msoFileDialogFolderPicker As Long = 4
    
    0 讨论(0)
提交回复
热议问题