1
我是VBA的新手,並且遇到了一個錯誤,指出:「對象需要」。我試圖從列1中的Excel工作表中獲取所有單元格,但是當我運行我的代碼時,會引發該錯誤。對象嘗試獲取列數時需要的錯誤
這是我的代碼:
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
最後一行拋出錯誤。我如何創建工作表對象?先進的謝謝你。我試過使用
Workbooks("Book1.xls").Sheet1.Columns(1)
但這也會引發錯誤。
編輯:我正在編輯和運行Outlook中的代碼,並有一個打開的Excel窗口。
工作簿(「Book1.xls」)。表(1).Columns(1) – Ralph
@Ralph Sheet1將工作,如果工作表確實命名爲Sheet1,則默認爲Sheet1。 –
您使用outlook展示的代碼以及您展示給您的問題所在的行使用Excel。你能顯示完整的代碼嗎? –