Attaching Excel through VBA

SimonJ

New Member
Joined
Jan 17, 2011
Messages
5
Hi,

I am trying to add a spreadsheet to an email and came across a code on another thread on here that works really well.

The only problem is that it sends the original saved version of my spreadsheet.

My user will be opening my spreadsheet from an intranet page and the vba will need to save a temporary copy for the user. Is there a way to change the code below so it saves a temporary copy and attaches that to an email instead of the original

Sub Button9_Click()

Dim OlApp As Object
Dim OlMail As Object
Dim ToRecipient As Variant

Set OlApp = CreateObject("Outlook.Application")
Set OlMail = OlApp.createitem(olMailItem)

For Each ToRecipient In Array("email.email.com", "Email2.email.com")
OlMail.Recipients.Add ToRecipient
Next ToRecipient

OlMail.subject = "Form" 'Subject field
OlMail.Attachments.Add ActiveWorkbook.FullName

OlMail.Display 'Display Email

End Sub



Thank You. Any help would be great
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,215,634
Messages
6,125,934
Members
449,275
Latest member
jacob_mcbride

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top