这个问题在这里已经有了答案:
Getting user-defined type not defined error when running code
(2 个回答)
3年前关闭。
我在运行程序以通过 Outlook 发送电子邮件时收到标题中提到的错误。有人可以帮忙吗?它突出显示了第二行 -
enter image description here昏暗 olApp 作为 Outlook.Application
代码:
Sub send_mail(address As String, subject As String, mail_body As String)
'
'
Dim **olApp As Outlook.Application**
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.mailitem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = address
olMail.subject = "Maintenance Activity at: " & subject
olMail.Body = "Equipment to be maintained: " & mail_body
olMail.CC = Sheets("Expiry").Range("M8").Value
olMail.send
End Sub
Sub mass_mail()
n = Now()
MsgBox "date: " & n
If MsgBox("Are You Sure? ", vbYesNo, " Warning! ") = vbYes Then
Dim row_number As Integer
row_number = 4
Do
DoEvents
row_number = row_number + 1
If Range("D" & row_number).Value >= n And Range("D" & row_number).Value < (n + 30) Then
Call send_mail(Sheet1.Range("L" & row_number), Sheet1.Range("C" & row_number), Sheet1.Range("D" & row_number))
MsgBox "Date: " & Range("D" & row_number).Value
End If
Loop Until row_number = 10
MsgBox ("Messages(s) Sent!")
End If
End Sub
最佳答案
早期绑定(bind)库引用:
您需要在项目引用中添加对 Outlook 库的引用。
在 Visual Basic 编辑器中,您需要转到工具 > 引用并向下滚动以找到适用于您的 Office 版本的 Microsoft Outlook 对象库
对我来说,这是 16.0 版
后期绑定(bind):
或者,您可以将库调用转换为后期绑定(bind),这不需要添加库引用,并且在将应用程序分发给可能具有不同 Office 版本的不同用户时更安全,其中:
Set olApp = CreateObject("Outlook.Application")
早期与晚期绑定(bind)的信息:
关于vba - '编译错误: User-defined type not defined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51905656/