Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 我能';t从主用户窗体打开用户窗体_Vba_Excel_Userform - Fatal编程技术网

Vba 我能';t从主用户窗体打开用户窗体

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

我正在使用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 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,好的。