我创建了一个包含14个项目的多选列表框。每个项目都会生成一个新工作簿,根据选择情况引入不同的工作表。目前,我正在尝试编写前两个项目(0和1),这些项目将在选中时生成新工作簿。此外,如果选择了项目0和1,则新工作簿应生成合并的工作表(如附加代码末尾的注释部分所示)。我的初始问题是,当选择第1项时,还会生成项目0的工作簿。因此,结果产生两个工作簿(属性和一般责任),而不仅仅是一个显示“责任”的工作簿。如果生成了项目0,它只生成我想要的属性,但是,我需要选择项目1才能生成“责任”工作表。另外,如何在项目代码末尾的注释部分中显示项目0和项目1多选项以生成两个工作表的合并?
非常感谢任何帮助。我在这里迸发出我的大脑。
代码:
Private Sub CMDSubSelector_Click()
SubmissionSelector.Hide
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Dim wbNew As Workbook
Set wbNew = ActiveWorkbook
Dim text As String
Dim i As Integer
For i = 0 To Me.Submissionlist.ListCount - 1
If Me.Submissionlist.Selected(i) = True Then
Sheets("SubmissionProperty").Visible = False
ThisWorkbook.Worksheets(Array("Client_Profile", "SubmissionProperty")).Copy
Sheets("SubmissionProperty").Visible = True
Worksheets("Client_Profile").Move Before:=Worksheets(1)
Worksheets("Client_Profile").Activate
End If
Next
For i = 0 To Me.Submissionlist.ListCount - 1
Me.Submissionlist.Selected(i) = False
Me.Submissionlist.Clear
Exit For
Next i
For i = 1 To Me.Submissionlist.ListCount - 1
If Me.Submissionlist.Selected(i) = True Then
Sheets("SubmissionLiabilty").Visible = False
ThisWorkbook.Worksheets(Array("Client_Profile", "SubmissionLiabilty")).Copy
Sheets("SubmissionLiabilty").Visible = True
Worksheets("Client_Profile").Move Before:=Worksheets(1)
Worksheets("Client_Profile").Activate
End If
Next
For i = 1 To Me.Submissionlist.ListCount - 1
Me.Submissionlist.Selected(i) = False
Me.Submissionlist.Clear
Exit For
Next i
'For i = 0 And i = 1 To Me.Submissionlist.ListCount - 1
'If Me.Submissionlist.Selected(i) = True Then
'Sheets("SubmissionProperty").Visible = False
'Sheets("SubmissionLiabilty").Visible = False
'ThisWorkbook.Worksheets(Array("Client_Profile", "SubmissionProperty", "SubmissionLiabilty")).Copy
'Sheets("SubmissionProperty").Visible = True
'Sheets("SubmissionLiabilty").Visible = True
'Worksheets("Client_Profile").Move Before:=Worksheets(1)
'Worksheets("Client_Profile").Activate
'End If
'Next
'For i = 0 And i = 1 To Me.Submissionlist.ListCount - 1
'Me.Submissionlist.Selected(i) = False
'Me.Submissionlist.Clear
'Exit For
'Next
If Me.Submissionlist.Value Then Unload Me
Application.ScreenUpdating = True
End Sub