Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 转发电子邮件或日历项目_Vba_Outlook - Fatal编程技术网

Vba 转发电子邮件或日历项目

Vba 转发电子邮件或日历项目,vba,outlook,Vba,Outlook,我正在使用VBA将电子邮件转发到一个地址。我也希望它转发日历邀请。当前,当针对日历邀请运行它时,我收到错误“运行时错误13,类型不匹配”,调试器突出显示“Set objMail=objItem.Forward” 是否有人知道如何转发电子邮件和日历邀请 Sub HelpdeskNewTicket() Dim helpdeskaddress As String Dim objMail As Outlook.MailItem Dim strbody As String Dim oldmsg A

我正在使用VBA将电子邮件转发到一个地址。我也希望它转发日历邀请。当前,当针对日历邀请运行它时,我收到错误“运行时错误13,类型不匹配”,调试器突出显示“Set 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
试试这个VBA:

Dim objMail作为对象

如果objMail的类型为mailItem或objMail的类型为MeetingItem,则