如何从用户表单向变量添加文本框值?

时间:2019-07-10 14:40:08

标签: excel vba

我创建了一个名为UIAutotestHeader的用户表单和一个名为pypath的文本框。然后在按钮上单击,我尝试将值传递给变量,但得到runtime error 424。请帮忙。

Sub LoopThroughFiles()
   Dim Path As String    
   UIAutotestHeader.Show
   Path = pypath.Value
   If pypath.Value = "" Then
       MsgBox "Please add a path having .py files."
   End If
End sub

按钮点击代码:

Private Sub CommandButton1_Click()
    UIAutotestHeader.Hide
End Sub

2 个答案:

答案 0 :(得分:1)

首先,请参阅有关使用UserForms的这一有用的RubberDuck Blog,它非常有用且适用。这就是我要基于的答案。


尝试使用public static function saveCompany( $params ) { if( $params ){ echo $params->userCompany; try { JPDO::beginTransaction(); $c = new Company(); $c->setuserCompany( $params->userCompany ); $c->setName( $params->name ); $c->setCoords( $params->coords ); $c->setcompanyPic( $params->companyPic ); $c->save(); JPDO::commit(); } catch ( JError $j ) { JPDO::rollback(); return [99]; } } return [1]; } 语句实例化您的用户窗体,以便您拥有它的捕获实例,您可以在其中访问所公开的各种属性。

请注意,在这种情况下,您不必存储变量,因为您仍然可以在用户窗体实例中访问它们。这是下面的示例。

With

在用户窗体中,您可以公开要访问的属性。我还添加了Sub LoopThroughFiles() With New UIAutotestHeader .Show If Not .IsCancelled Then If .PyPath = "" Then MsgBox "Please add a path having .py files." End If End If End With End Sub 方法,以确保用户没有按“取消”。

IsCancelled

答案 1 :(得分:0)

尝试此代码

'In Standard Module
'------------------
Public sPath As String

Sub LoopThroughFiles()
Load UIAutotestHeader
sPath = UIAutotestHeader.pypath.Value
UIAutotestHeader.Show
End Sub

'In UserForm Module
Private Sub pypath_AfterUpdate()
If sPath = "" Then
    MsgBox "Please add a path having .py files."
End If
End Sub

Private Sub CommandButton1_Click()
If sPath <> "" Then MsgBox sPath
sPath = ""
Unload UIAutotestHeader
End Sub
相关问题