错误1004主题不在工作表函数中

时间:2015-02-09 05:03:19

标签: excel vba excel-vba

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"页面,我一直在收到错误,无法解决它。 请帮忙

1 个答案:

答案 0 :(得分:0)

您认为您正在打开的工作簿是Workbooks集合中的第一个可能不正确的工作簿。假设您的wksSubjectAreawksFilter都在刚刚打开工作簿中,请更改以下行:

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