Private Sub Workbook_Open()
Dim wksSubjectArea As Worksheet
Dim wksFilter As Worksheet
Dim strSubArea As String
Set wksSubjectArea = Application.Workbooks(1).Worksheets(3)
Set wksFilter = Application.Workbooks(1).Worksheets(4)
Sheet4.cmbFilter.Clear
wksSubjectArea.Select -Error Line
wksSubjectArea.Range("F2").Select
Do Until IsEmpty(ActiveCell)
strSubArea = ActiveCell
wksFilter.Select
Sheet4.cmbFilter.AddItem strSubArea
wksSubjectArea.Select
ActiveCell.Offset(1, 0).Select
Loop
Sheet4.cmbFilter.Text = ""
这是在" ThisWorkBook"页面,我一直在收到错误,无法解决它。 请帮忙
答案 0 :(得分:0)
您认为您正在打开的工作簿是Workbooks
集合中的第一个可能不正确的工作簿。假设您的wksSubjectArea
和wksFilter
都在刚刚打开工作簿中,请更改以下行:
Set wksSubjectArea = Application.Workbooks(1).Worksheets(3)
Set wksFilter = Application.Workbooks(1).Worksheets(4)
进入这些:
Set wksSubjectArea = ThisWorkbook.Worksheets(3)
Set wksFilter = ThisWorkbook.Worksheets(4)
此外,但不一定,您可以在错误行中使用.Activate
代替.Select
。