通过工作簿中的工作表循环问题

时间:2014-11-03 20:59:58

标签: excel vba excel-vba

我在课堂上有家庭作业的调试问题,我做了我认为必要但我得到错误的更改。对于我在消息框中method or data member not found的代码,它显示shtCurrent.name

我已尽可能多地研究,但我找不到答案。任何人都可以帮助我吗?

谢谢。

Public Sub PrintWorksheets1()
    'declare variables and assign address to object variable
    Dim strPrint As String, wkbHours As Workbook, shtCurrent As Worksheets
    Set wkbHours = Application.Workbooks("auco6215_HW10_Ex9.xlsm")
    wkbHours.Activate
    'ask user if he or she wants to print the worksheet
    For Each shtCurrent In wkbHours.Worksheets
        strPrint = _
            MsgBox(prompt:="Print " & shtCurrent.Name & "?", Buttons:=vbYesNo + vbExclamation)
        If strPrint = vbYes Then        'if user wants to print
            shtCurrent.PrintPreview
        End If
    Next shtCurrent
End Sub

1 个答案:

答案 0 :(得分:4)

shtCurrent As Worksheets不应该是工作表 S 集合,只是工作表对象。

Dim strPrint As String, wkbHours As Workbook, shtCurrent As Worksheet