使用VBA将Outlook邮件转换为excel

使用VBA将Outlook邮件转换为excel,outlook,automation,Outlook,Automation,这是来自YouTube视频的代码。下面的代码给出了一个编译器错误:未定义Userdefined类型 Sub SendEmail(what_address As String, Subject_line As String, mail_body As String) 'Dim olApp As Outlook.Application Set olApp = CreateObject("outlook.Application") 'Dim olMail As Outlook.MailItem Se

这是来自YouTube视频的代码。下面的代码给出了一个编译器错误:未定义Userdefined类型

Sub SendEmail(what_address As String, Subject_line 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 = what_address
olMail.Subject = Subject_line
olMail.body = mial_body
olMail.send
End Sub

Sub SendMassEmail()
row_number = 1
Do
DoEvents
row_number = row_number + 1
Dim mail_body_message As String
Dim full_name As String
Dim Promoscode As String

mail_body_message = Sheet1.Range("J2")
full_name = Sheet1.Range("B" & row_number) & " " & Sheet1.Range("C" & row_number)
promo_code = Sheet1.Range("D" & row_number)
mial_body_message = Replace(mail_body_message, "replace_name_here", full_name)

Call SendEmail(Sheet1.Range("A1" & row_number), "This is a test e-mail", mail_body_message)

Loop Until row_number = 6

End Sub
我有一个编译器错误,我已检查了所有内容,但…不确定是什么导致了此问题。

使用MailItem类的属性指定收件人,而不是属性

Recipients类提供了允许创建新收件人并将其添加到集合中的方法。然后使用该方法尝试根据通讯簿解析收件人对象

Sub AssignTask()  
  Dim myItem As Outlook.TaskItem  
  Dim myDelegate As Outlook.Recipient 
  Set MyItem = Application.CreateItem(olTaskItem)  
  MyItem.Assign  
  Set myDelegate = MyItem.Recipients.Add("DL name")  
  myDelegate.Resolve  
  If myDelegate.Resolved Then  
    myItem.Subject = "Prepare Agenda For Meeting"  
    myItem.DueDate = Now + 30  
    myItem.Display  
    myItem.Send  
  End If  
End Sub

我的代码工作得很好,但唯一的问题是消息体。我需要在发送电子邮件之前编辑邮件。现在它不允许我编辑邮件正文。是的!用户定义类型未定义…我正在使用来自youtube视频的代码。第1行子SendEmail(what_address作为字符串,Subject_Line作为字符串,mail_body作为字符串)“olApp作为新Outlook.Application”错误作为编译器错误:用户定义类型未定义debugging将在olMail.body=minal_body中突出显示“minal_body”。否这不是获取我的olMail.To=what_address