简体   繁体   中英

Using Textbox as procedure(sub) input parameter

I have some trouble with my code. I'll be glad if you can help me to where i am wrong.

This is my sheet's (name is SetSheet) code section; cmdSelProjectDir_Click() is my ActiveX command button which i try to select my working directory. SetSheet.txtSetWorkDir is my ActiveX textbox, selected directory path written into this. GetFolder(txtDir) is my procedure i call it from "Settings" module.

But i didn't built in proper way it gaves an error like that "Type Mismatch". But i don't know how is it possible to apply this type of strcture to code because i will be use this GetFolder subprocedure also on my other sheets.

'/SetSheet Page
    Sub cmdSelProjectDir_Click()
    Dim txtDir As TextBox
    Set txtDir = SetSheet.txtSetWorkDir
    Call Settings.GetFolder(txtDir)
    End Sub

And here my procedure;

'/GetFolder procedure from Settings module.

    Sub GetFolder(txtDir As TextBox)
        Dim fdo As FileDialog
        Dim sDir As String
        Set fdo = Application.FileDialog(msoFileDialogFolderPicker)
        With fdo
            .Title = "Select a Directory"
            .AllowMultiSelect = False
            .InitialFileName = Application.DefaultFilePath
            If .Show <> -1 Then GoTo NextCode
            sDir = .SelectedItems(1)
            txtDir.Value = sDir
            Debug.Print txtDir.Value; sDir

        End With
    NextCode:
    '    GetFolder = sDir
        Set fdo = Nothing
    End Sub

You have to use MSForms.TextBox instead of TextBox for an ActiveX text box:

Dim txtDir As MSForms.TextBox

and

Sub GetFolder(txtDir As MSForms.TextBox)

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