Send OLE object as attachment (1 Viewer)

ppataki

Registered User.
Local time
Today, 10:11
Joined
Sep 5, 2008
Messages
267
Dear All,

I have a form that contains an unbound OLE object (xlsx file)
I would need to send that as an attachment in an email
In my code I use:

olattach.Add Me.OLEobject

but I get an error message that object does not support this property or method

Could you please advise?
Many thanks
 

Trevor G

Registered User.
Local time
Today, 18:11
Joined
Oct 1, 2009
Messages
2,341
I think you have to state where the workbook is located. I have copied a procedure which sends multiple objects, the basis I hope will help you.

Option Compare Database
Function sndrpt()
Rem <!-- Make sure the Microsoft Object xx.0 Reference Library is enabled & _
(found under Tools>References in the VBA Editor) -->

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strAttach1 As String
Dim strAttach2 As String
Dim strAttach3 As String
Dim strAttach4 As String
Dim strAttach5 As String

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'Output Reports
Rem <!-- change "Reportx" to match the report names you wish to export. & _
IMPORTANT: Make sure the location you select to save your reports to exists, Access will & _
not create the folders for you. -->
DoCmd.OutputTo acOutputReport, "Report1", acFormatRTF, "C:\YourFolder\Report1.rtf", False
DoCmd.OutputTo acOutputReport, "Report2", acFormatRTF, "C:\YourFolder\Report1.rtf", False
DoCmd.OutputTo acOutputReport, "Report3", acFormatRTF, "C:\YourFolder\Report1.rtf", False
DoCmd.OutputTo acOutputReport, "Report4", acFormatRTF, "C:\YourFolder\Report1.rtf", False
DoCmd.OutputTo acOutputReport, "Report5", acFormatRTF, "C:\YourFolder\Report1.rtf", False

'Set Attachments
Rem <!-- make sure to correlate the attachments to each of the reports you wish to send -->
strAttach1 = "C:\YourFolder\Report1.rtf"
strAttach2 = "C:\YourFolder\Report2.rtf"
strAttach3 = "C:\YourFolder\Report3.rtf"
strAttach4 = "C:\YourFolder\Report4.rtf"
strAttach5 = "C:\YourFolder\Report5.rtf"

'Generate email
With objEmail
.To = "email@removed.com"
.Subject = "Your subject here"
.Body = "Message in body of email here"
.Display
.Attachments.Add strAttach1
.Attachments.Add strAttach2
.Attachments.Add strAttach3
.Attachments.Add strAttach4
.Attachments.Add strAttach5
End With

'Remove attachments from drive
Kill strAttach1
Kill strAttach2
Kill strAttach3
Kill strAttach4
Kill strAttach5

End Function
 

ppataki

Registered User.
Local time
Today, 10:11
Joined
Sep 5, 2008
Messages
267
Thank you but is there a way to skip saving the attachment as a file?
So the OLE object could be sent as an attachment without first being saved in a file on the hard disk...
Cheers
 

Trevor G

Registered User.
Local time
Today, 18:11
Joined
Oct 1, 2009
Messages
2,341
I don't believe you can do that, I understand that it should have a path to the object then it can be sent.

When you have created the OLE does it not come from an Excel File that is already saved on your system?
 

Users who are viewing this thread

Top Bottom