在工作簿中循环执行工作表 [英] Issue looping through worksheets in a workbook
本文介绍了在工作簿中循环执行工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
方法或数据成员未找到
,代码为 shtCurrent.name
,位于消息框中。 / p> 我已经尽可能地进行了研究,但是找不到答案。有人可以帮我吗?
谢谢。
PrintWorksheets1()
'声明变量并将地址分配给对象变量
Dim strPrint As String,wkbHours As Workbook,shtCurrent As Worksheets
设置wkbHours = Application.Workbooks(auco6215_HW10_Ex9.xlsm)
wkbHours.Activate
'询问用户是否要打印工作表
对于每个shtCurrent在wkbHours.Worksheets
strPrint = _
MsgBox(prompt:=打印& shtCurrent.Name&?,Buttons:= vbYesNo + vbExclamation)
如果strPrint = vbYes然后'如果用户想要打印
shtCurrent.PrintPreview
End If
Next shtCurrent
End Sub
解决方案
shtCurrent As Worksheets
不应该是工作表 S 集合,只是工作表对象。
狄m strPrint As String,wkbHours As Workbook,shtCurrent As Worksheet
I have a debugging problem for homework in class and I made the changes I saw that were necessary but I am getting an error. It says method or data member not found
for my code that is shtCurrent.name
that is in the message box.
I have researched as much as possible but I cannot find an answer. Can anyone help me out?
Thank you.
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
解决方案
The shtCurrent As Worksheets
should not be the worksheetS collection, just the worksheet object.
Dim strPrint As String, wkbHours As Workbook, shtCurrent As Worksheet
这篇关于在工作簿中循环执行工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文