D
draco
Hi
I'm writing a macro in Outlook, and part of the functionality is to
reference the currently selected mail and to send it as an attachment
in another mail.
I know this functionality exists in Outlook, so it should be possible
to reproduce it in a macro.
So I have my function that sets up a mail:
'send mail
Dim objMail As Outlook.MailItem
Set objMail = ThisOutlookSession.CreateItem(olMailItem)
objMail.To = ...
objMail.Attachments.Add (GetSelectedMail)
objMail.Send
I'm not sure about that Attachments.Add function - it should specify
the parameter is a reference type rather than a file path but I'm not
sure how.
And here is the function to get the attachment:
Private Function GetSelectedMail() As Outlook.MailItem
Dim objSelection As Outlook.Selection
Set objSelection = ThisOutlookSession.ActiveExplorer.Selection
Dim objMailItem As Outlook.MailItem
If objSelection.Count = 0 Then
objMailItem = Nothing
Else
objMailItem = objSelection.Item(1)
End If
GetSelectedMail = objMailItem
End Function
This is not working. I get an error at this line:
objMailItem = objSelection.Item(1)
...object variable or with block variable not set...
Any ideas??
I'm writing a macro in Outlook, and part of the functionality is to
reference the currently selected mail and to send it as an attachment
in another mail.
I know this functionality exists in Outlook, so it should be possible
to reproduce it in a macro.
So I have my function that sets up a mail:
'send mail
Dim objMail As Outlook.MailItem
Set objMail = ThisOutlookSession.CreateItem(olMailItem)
objMail.To = ...
objMail.Attachments.Add (GetSelectedMail)
objMail.Send
I'm not sure about that Attachments.Add function - it should specify
the parameter is a reference type rather than a file path but I'm not
sure how.
And here is the function to get the attachment:
Private Function GetSelectedMail() As Outlook.MailItem
Dim objSelection As Outlook.Selection
Set objSelection = ThisOutlookSession.ActiveExplorer.Selection
Dim objMailItem As Outlook.MailItem
If objSelection.Count = 0 Then
objMailItem = Nothing
Else
objMailItem = objSelection.Item(1)
End If
GetSelectedMail = objMailItem
End Function
This is not working. I get an error at this line:
objMailItem = objSelection.Item(1)
...object variable or with block variable not set...
Any ideas??