Có ai biết tại sao tôi nhận được lỗi "do người dùng xác định không được xác định" trong số Function GetOutlookApp() As Outlook.Application
ở cuối mã này không?Lỗi do người dùng xác định không xác định khi chạy mã
Sub CreateAppointments()
Dim cell As Excel.Range
Dim rng As Excel.Range
Dim wholeColumn As Excel.Range
Dim startingCell As Excel.Range
Dim oApp As Outlook.Application
Dim tsk As Outlook.TaskItem
Dim wkbk As Excel.Workbook
Dim wksht As Excel.Worksheet
Dim lastRow As Long
Dim arrData As Variant
Dim i As Long
'bắt đầu ứng dụng Outlook
Set oApp = GetOutlookApp
If oApp Is Nothing Then
MsgBox "Could not start Outlook.", vbInformation
Exit Sub
End If
' get phạm vi bảng tính thành một mảng trong một đi
Set wkbk = ActiveWorkbook
Set wksht = wkbk.ActiveSheet
Set wholeColumn = wksht.Range("B:B")
lastRow = wholeColumn.End(xlDown).Row - 2
Set startingCell = wksht.Range("B2")
Set rng = wksht.Range(startingCell, startingCell.Offset(lastRow, 1))
arrData = Application.Transpose(rng.Value)
'lặp qua mảng và tạo ra nhiệm vụ cho mỗi bản ghi
For i = LBound(arrData, 2) To UBound(arrData, 2)
Set tsk = oApp.CreateItem(olTaskItem)
With tsk
.DueDate = arrData(2, i)
.Subject = arrData(1, i)
.Save
End With
Next I
End Sub
Function GetOutlookApp() As Outlook.Application
On Error Resume Next
Set GetOutlookApp = CreateObject("Outlook.Application")
End Function
Did bạn thêm một tham chiếu đến máy chủ COM văn phòng? * Công cụ> Tài liệu tham khảo> đánh dấu vào Thư viện đối tượng của Microsoft Outlook XXX * –
Bingo! Đó là nó Cảm ơn! –
Bản sao có thể có của [Loại do người dùng xác định không được xác định - Macro Excel] (http: //stackoverflow.com/questions/24261557/user-defined-type-not-defined-excel-macros) –