转发电子邮件或日历项目

时间:2014-07-07 11:27:34

标签: vba outlook

我使用VBA将电子邮件转发到某个地址。我也喜欢转发日历邀请。目前,当针对日历邀请运行时,我收到错误'运行时错误13,类型不匹配'并且调试器突出显示"设置objMail = objItem.Forward"。

是否有人知道这种方式可用于转发电子邮件和日历邀请?

Sub HelpdeskNewTicket() 
Dim helpdeskaddress As String 
Dim objMail As Outlook.MailItem 
Dim strbody As String 
Dim oldmsg As String 
Dim senderaddress As String 
Dim addresstype As Integer

' Set this variable as your helpdesk e-mail address 
helpdeskaddress = "testemail@generic.com"

Set objItem = GetCurrentItem() 
Set objMail = objItem.Forward

' Sender E=mail Address 
senderaddress = objItem.SenderEmailAddress

'Searches for @ in the email address to determine if it is an exchange user 
addresstype = InStr(senderaddress, "@")

' If the address is an Exchange DN use the Senders Name 
If addresstype = 0 Then 
    senderaddress = objItem.SenderName 
End If

'adds the senders e-mail address as the created by object for the ticket and appends the message body 
strbody = "#created by " & senderaddress & vbNewLine & vbNewLine & objItem.Body

objMail.To = helpdeskaddress 
objMail.Subject = objItem.Subject 
objMail.Body = strbody

' remove the comment from below to display the message before sending 
'objMail.Display

'Automatically Send the ticket 
objMail.Send

MsgBox "This email has been forwarded to ITsupport"

Set objItem = Nothing 
Set objMail = Nothing 
End Sub

Function GetCurrentItem() As Object 
Dim objApp As Outlook.Application 
Set objApp = Application 
On Error Resume Next 
Select Case TypeName(objApp.ActiveWindow) 
    Case "Explorer" 
        Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1) 
    Case "Inspector" 
        Set GetCurrentItem = objApp.ActiveInspector.CurrentItem 
    Case Else 
End Select 
End Function

1 个答案:

答案 0 :(得分:0)

试试这个VBA:

Dim objMail As Object

如果TypeOf objMail是mailItem或TypeOf objMail是MeetingItem那么