简体   繁体   English

使用文本框作为过程(子)输入参数

[英]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; 这是我的工作表(名称为SetSheet)的代码部分; cmdSelProjectDir_Click() is my ActiveX command button which i try to select my working directory. cmdSelProjectDir_Click()是我的ActiveX命令按钮,我尝试选择我的工作目录。 SetSheet.txtSetWorkDir is my ActiveX textbox, selected directory path written into this. SetSheet.txtSetWorkDir是我的ActiveX文本框,将选定的目录路径写入其中。 GetFolder(txtDir) is my procedure i call it from "Settings" module. GetFolder(txtDir)是我从“设置”模块中调用的过程。

But i didn't built in proper way it gaves an error like that "Type Mismatch". 但是我没有以正确的方式构建它会给出类似“ 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. 但是我不知道如何将这种类型的结构应用于代码,因为我还将在其他工作表上使用此GetFolder子过程。

'/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: 您必须为ActiveX文本框使用MSForms.TextBox而不是TextBox

Dim txtDir As MSForms.TextBox

and

Sub GetFolder(txtDir As MSForms.TextBox)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM