对象项不支持此属性或方法 [英] Object Item does not support this property or method
问题描述
我不断收到错误对象不在以*开头的行上支持此属性或方法
。我花了最后一小时试图弄清楚为什么出现这个错误,因为工作簿
具有属性 Sheets
code>单元格返回一个值。
Sub Send_Reminder_Email()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
Dim xlApp As Object,wb As Object
Dim row As Integer
设置xlApp = CreateObject(Excel.Application)
设置wb = xlApp.Workbooks.Open(C:\User\Me\ ... file.xls)
row = 2
* Do While Not IsEmpty(wb.Sheets.Cells(row,2).Value)
objMsg.To = wb.Sheets.Cells(row,6)
objMsg.BCC =potapeno@foo.net
objMsg.Subject =电子邮件
objMsg.Body =信息
objMsg.Send
row = row + 1
循环
设置objMsg =没有
设置wb =没有
设置xlApp =没有
row = 0
End Sub
我也尝试激活工作簿,但无法解决我的问题。我不知道什么对象不支持什么方法。
wb.Sheets
是一个集合,没有 .Cells
属性。您可以使用对象浏览器在VBA项目中按 F2 来浏览方法和属性。输入课程名称,然后按搜索按钮:
要获取某个Worksheet对象必须指定工作表集合e的项目。 G。通过工作表名称:
Do Is not IsEmpty(wb.Sheets.Item(Sheets1)。Cells(row,2) $ v
$ / code $ <$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ / code>是一个默认属性,但是它是这样的,因此您可以以简化的形式调用它: 而不是IsEmpty(wb.Sheets(Sheets1)。Cells(row,2).Value)
或通过工作表索引:
Do Is not IsEmpty(wb.Sheets(1).Cells(row,2).Value )
So, I'm a beginner when it comes to VBA, but I'm trying to create a simple way to send a reminder message to a bunch of people whose information is found on an excel spreadsheet. It is supposed to loop, sending emails to addresses found in the column until there is an empty cell.
I keep getting the error Object does not support this property or method
on the line that begins with a *. I have spent the last hour trying to figure out why this error is appearing because Workbooks
have the property Sheets
which have Cells
which return a value.
Sub Send_Reminder_Email()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
Dim xlApp As Object, wb As Object
Dim row As Integer
Set xlApp = CreateObject("Excel.Application")
Set wb = xlApp.Workbooks.Open("C:\User\Me\...file.xls")
row = 2
*Do While Not IsEmpty(wb.Sheets.Cells(row, 2).Value)
objMsg.To = wb.Sheets.Cells(row, 6)
objMsg.BCC = "potapeno@foo.net"
objMsg.Subject = "Email"
objMsg.Body = "Information"
objMsg.Send
row = row + 1
Loop
Set objMsg = Nothing
Set wb = Nothing
Set xlApp = Nothing
row = 0
End Sub
I have also tried "activating" the workbook, but it fails to solve my problem. I can't figure out what object doesn't support what method.
解决方案 wb.Sheets
is a collection and doesn't have .Cells
property. You can explore methods and properties with Object Browser pressing F2 in VBA Project. Enter class name and press Search button:
To get a certain Worksheet object you have to specify the item of the worksheets collection e. g. by worksheet name:
Do While Not IsEmpty(wb.Sheets.Item("Sheets1").Cells(row, 2).Value)
It may be not quite obvious that .Item()
is a default property, but so it is, thus you can call it in reduced form:
Do While Not IsEmpty(wb.Sheets("Sheets1").Cells(row, 2).Value)
Or by worksheet index:
Do While Not IsEmpty(wb.Sheets(1).Cells(row, 2).Value)
这篇关于对象项不支持此属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!