Vba 我能';t从主用户窗体打开用户窗体
我正在使用Excel 2013 vba。我有两种表格:frmMain和。在frmMain中,我只有一个带有代码UserForm1.show的cmd按钮,但是我无法打开UserForm1 这是我的密码:Vba 我能';t从主用户窗体打开用户窗体,vba,excel,userform,Vba,Excel,Userform,我正在使用Excel 2013 vba。我有两种表格:frmMain和。在frmMain中,我只有一个带有代码UserForm1.show的cmd按钮,但是我无法打开UserForm1 这是我的密码: Private Sub Workbook_Open() Application.Visible = False 'This code hides the workbook UserForm1.Show 'Brings the UserForm End
Private Sub Workbook_Open()
Application.Visible = False 'This code hides the workbook
UserForm1.Show 'Brings the UserForm
End Sub
'模块1代码
Sub hidden()
Sheet1.Visible = False
End Sub
我的UserForm1的屏幕截图
UserForm1的代码
'Application.ScreenUpdating = False
'Sheets("Sheet1").Visible = True
Private Sub cmbCalltype_Change()
'==========sayon rani dri=======
'If cmbCalltype.List(cmbCalltype.ListIndex) = "Training" Then
' cmbGc.Enabled = False
'ElseIf cmbCalltype.List(cmbCalltype.ListIndex) = "Wrong GC" Then
' cmbGc.Enabled = False
'ElseIf cmbCalltype.List(cmbCalltype.ListIndex) = "Wrong Number" Then
' cmbGc.Enabled = False
'ElseIf cmbCalltype.List(cmbCalltype.ListIndex) = "Resident" Then
' cmbGc.Enabled = False
'Else
' cmbGc.Enabled = True
'End If
If cmbCalltype.Text = "Training" Then
cmbGc.Enabled = False
ElseIf cmbCalltype.Text = "Resident" Then
cmbGc.Enabled = False
ElseIf cmbCalltype.Text = "Wrong GC" Then
cmbGc.Enabled = False
ElseIf cmbCalltype.Text = "Wrong Number" Then
cmbGc.Enabled = False
Else
cmbGc.Enabled = True
End If
End Sub
Private Sub cmdApplicationshow_Click()
Application.Visible = True 'This will open the excel file...
End Sub
Private Sub cmdClear_Click()
'==========sayon rani dri=======
'Call UserForm_Initialize
txtName.Value = ""
cmbCalltype.Value = ""
cmbGc.Value = ""
cmbVisit.Value = ""
End Sub
Private Sub cmdHidden_Click()
Application.Visible = False 'This will open the excel file...
End Sub
Private Sub cmdMove_Click()
'Dim emptyRow As Long
'Sheet1.Activate 'Make Sheet1 active
'emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
'Cells(emptyRow, 1).Value = txtName.Value
'Cells(emptyRow, 2).Value = cmbCalltype.Value
'Cells(emptyRow, 3).Value = cmbVisit.Value
With Sheet1
With .Range("A" & .Rows.Count).End(xlUp)
.Offset(1).Resize(1, 4).Value = Array(txtName.Value, cmbCalltype.Value, cmbGc.Value, cmbVisit.Value)
End With
txtLeasing.Value = Application.CountIf(.Columns(2), "Leasing") 'counting the number of instances leasing text occur
txtGc.Value = Application.CountIf(.Columns(3), "Yes")
'txtYes.Value = Application.CountIf(.Columns(4), "Yes")
'txtNo.Value = Application.CountIf(.Columns(4), "No")
txtPercentage.Value = txtGc.Value / txtLeasing.Value * 100
''==================
txtVisLeasing.Value = txtLeasing.Value
txtTotvisit.Value = Application.CountIf(.Columns(4), "Yes")
txtVisitper.Value = txtTotvisit.Value / txtVisLeasing * 100
End With
End Sub
Private Sub UserForm_Initialize()
'Worksheets("Sheet1").Activate
'Sheets("Sheet1").Visible = False
txtName.Value = "" 'Empty Customer
cmbCalltype.Value = "" 'Empty Call Type
cmbGc.Value = "" 'Empty GC
cmbVisit.Value = "" 'Empty Visit
cmbCalltype.Clear
With cmbCalltype
.AddItem "Leasing"
.AddItem "Training"
.AddItem "Resident"
.AddItem "Wrong GC"
.AddItem "Wrong Number"
End With
cmbGc.Clear
With cmbGc
.AddItem "Yes"
.AddItem "No"
End With
cmbVisit.Clear
With cmbVisit
.AddItem "Yes"
.AddItem "No"
End With
txtName.SetFocus
End Sub
从
Workbook\u Open()
调用的UserForm1
实例是否与从frmMain
调用的UserForm1
实例相同
- 如果Yes,则创建一个模块,并将
中的Module1
实例声明为UserForm1
Public
- 如果No,则在
中声明frmMain
的表单级实例UserForm1
'frmMain Code
Dim fUser As UserForm1
Private Sub CommandButton1_Click()
If fUser Is Nothing Then
fUser = New UserForm1
End If
fUser.Show
End Sub
“无法打开UserForm1”是什么意思?启动时?这是你在显示的代码中打开它的唯一地方。嗨,Mukul,可以把这两个文件发送给你吗?@DylanMecagami,好的。