0

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
2
  • Which row throws the error? Commented Feb 1, 2018 at 8:19
  • @teylyn At the beginning Set txtDir = SetSheet.txtSetWorkDir Commented Feb 1, 2018 at 8:25

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.