我遇到一个小问题,希望您能提供帮助。我创建了一个带有一组复选框的用户窗体。想法是您可以选中过滤器/复制/粘贴的类型复选框,然后单击确定,它将运行。问题在于,只要选中该框,它就会立即运行,而不是等待。我确定我的订单搞砸了,或者我需要一个if语句,但是对于我自己的一生,我不知道如何使它生效。我已经包含了按钮的代码以及“确定”和“取消”按钮的代码。
任何帮助将不胜感激!
Private Sub CheckBox1_Click()
End Sub
Private Sub CheckBox2_Click()
End Sub
Private Sub CheckBox3_Click()
End Sub
Private Sub CheckBox4_Click()
End Sub
Private Sub CheckBox5_Click()
End Sub
Private Sub CheckBox6_Click()
End Sub
Public Property Get IsCancelled() As Boolean
IsCancelled = cancelled
End Property
Private Sub OkButton_Click()
Dim sh As Worksheet
Dim rang As Range
Select Case True
Case CheckBox1.Enabled
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=1, Criteria1:="NN"
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=21, Criteria1:="FALSE"
Set sh = Worksheets("Country")
Set rang = sh.UsedRange.Offset(1, 0)
On Error Resume Next
Set rang = rang.SpecialCells(xlCellTypeVisible).Copy
Worksheets("PPage").Activate
Worksheets("PPage").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Selection.Range("G1:R" & lrow).ClearContents
Selection.Range("V1:AB" & lrow).Delete
sh.Activate
Application.CutCopyMode = False
Range("A1").Select
Case CheckBox2.Enabled
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=1, Criteria1:="NC"
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=21, Criteria1:="FALSE"
Set sh = Worksheets("Country")
Set rang = sh.UsedRange.Offset(1, 0)
On Error Resume Next
Set rang = rang.SpecialCells(xlCellTypeVisible).Copy
Worksheets("PPage").Activate
Worksheets("PPage").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Selection.Range("G1:R" & lrow).ClearContents
Selection.Range("V1:AB" & lrow).Delete
sh.Activate
Application.CutCopyMode = False
Range("A1").Select
Case CheckBox3.Enabled
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=1, Criteria1:="NF"
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=21, Criteria1:="FALSE"
Set sh = Worksheets("Country")
Set rang = sh.UsedRange.Offset(1, 0)
On Error Resume Next
Set rang = rang.SpecialCells(xlCellTypeVisible).Copy
Worksheets("PPage").Activate
Worksheets("PPage").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Selection.Range("G1:R" & lrow).ClearContents
Selection.Range("V1:AB" & lrow).Delete
sh.Activate
Application.CutCopyMode = False
Range("A1").Select
Case CheckBox4.Enabled
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=1, Criteria1:="NT"
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=21, Criteria1:="FALSE"
Set sh = Worksheets("Country")
Set rang = sh.UsedRange.Offset(1, 0)
On Error Resume Next
Set rang = rang.SpecialCells(xlCellTypeVisible).Copy
Worksheets("PPage").Activate
Worksheets("PPage").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Selection.Range("G1:R" & lrow).ClearContents
Selection.Range("V1:AB" & lrow).Delete
sh.Activate
Application.CutCopyMode = False
Range("A1").Select
Case CheckBox5.Enabled
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=1, Criteria1:="NB"
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=21, Criteria1:="FALSE"
Set sh = Worksheets("Country")
Set rang = sh.UsedRange.Offset(1, 0)
On Error Resume Next
Set rang = rang.SpecialCells(xlCellTypeVisible).Copy
Worksheets("PPage").Activate
Worksheets("PPage").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Selection.Range("G1:R" & lrow).ClearContents
Selection.Range("V1:AB" & lrow).Delete
sh.Activate
Application.CutCopyMode = False
Range("A1").Select
Case CheckBox6.Enabled
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=1, Criteria1:="NR"
ActiveSheet.Range("$A$1:$AE$10000").AutoFilter Field:=21, Criteria1:="FALSE"
Set sh = Worksheets("Country")
Set rang = sh.UsedRange.Offset(1, 0)
On Error Resume Next
Set rang = rang.SpecialCells(xlCellTypeVisible).Copy
Worksheets("PPage").Activate
Worksheets("PPage").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Selection.Range("G1:R" & lrow).ClearContents
Selection.Range("V1:AB" & lrow).Delete
sh.Activate
Application.CutCopyMode = False
Range("A1").Select
End Select
Hide
End Sub
Private Sub CancelButton_Click()
OnCancel
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = VbQueryClose.vbFormControlMenu Then
Cancel = True
OnCancel
End If
End Sub
Private Sub OnCancel()
cancelled = True
Hide
End Sub
答案 0 :(得分:1)
您需要将checkbox_click事件中的代码放入按钮OK事件中,如下所示:
$table = $section->addTable([
'unit' => Table::WIDTH_PERCENT,
'width' => 100 * 50,
'borderSize' => 10
]);
$table->addRow();
$table->addCell(null, [
'borderSize' => 4
])->addText($content[$i]);
----
$table = $section->addTable([
'unit' => Table::WIDTH_PERCENT,
'width' => 100 * 50,
'borderSize' => 10,
'borderStyle' => 'dbl'
]);
$table->addRow();
$table->addCell(null, [
'borderSize' => 4
])->addText($content[$i]);