Object尝试获取列数时要求的错误

我是新来的VBA,我已经提出了一个错误,指出:“所需的对象”。 我试图从我的Excel工作表中的所有单元格列1,但是当我运行我的代码,它会引发错误。

这是我的代码:

Public Sub emailList() 'Setting up the Excel variables. Dim olApp As Object Dim olMailItm As Object Dim iCounter As Integer Dim Dest As Variant Dim SDest As String 'Create the Outlook application and the empty email. Set olApp = CreateObject("Outlook.Application") Set olMailItm = olApp.CreateItem(0) 'Using the email, add multiple recipients, using a list of addresses in column A. With olMailItm SDest = "" For iCounter = 1 To WorksheetFunction.CountA(Workbooks("Book1.xls").Sheets(1).Columns(1)) If SDest = "" Then SDest = Range.Cells(iCounter, 1).Value Else SDest = SDest & ";" & Range.Cells(iCounter, 1).Value End If Next iCounter 'Do additional formatting on the BCC and Subject lines, add the body text from the spreadsheet, and send. .BCC = SDest .Subject = "FYI" .Body = ActiveSheet.TextBoxes(1).Text .Send End With 'Clean up the Outlook application. Set olMailItm = Nothing Set olApp = Nothing End Sub 

最后一行是抛出错误。 我如何创build一个工作表对象? 先进的谢谢你。 我试过使用

 Workbooks("Book1.xls").Sheet1.Columns(1) 

但是这也会引发错误。

编辑:我正在编辑和运行Outlook中的代码,并有一个打开的Excel窗口。

您将需要在工具/添加引用下添加对Excel对象库的引用,这是在VBA编辑器中完成的。 仅仅打开Excel是不够的。