PDA

View Full Version : A macro for emailing a workbook



K. Georgiadis
05-04-2006, 06:22 AM
How can I create a macro for the users, assigned to a button, which automatically sends a completed workbook as an attachment to my email address?

I thought I might figure it out by recording the steps, but the recording only shows the email compositions screen, not the address that was selected in the recording.

PS: I tried to simply insert my email address to the appropriate worksheet, but that did not seem to work

lucas
05-04-2006, 06:31 AM
Try this, its what I use:

Sub emailToSteve()
Application.Dialogs(xlDialogSendMail).Show arg1:="you@yahoo.com"
End Sub


uses outlook

K. Georgiadis
05-04-2006, 06:46 AM
can I add a command to send so that the user does not have to do anything further?

lucas
05-04-2006, 06:54 AM
This one will do that for you and has some more configuration for the subject line, etc.

Option Explicit
Sub eMailActiveWorkbook()
Dim OL As Object
Dim EmailItem As Object
Dim Wb As Workbook
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Wb = ActiveWorkbook
Wb.Save
With EmailItem
.Subject = "Insert Subject Here"
.Body = "Insert message here" & vbCrLf & _
"Line 2" & vbCrLf & _
"Line 3"
.To = "User@Domain.Com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Wb.FullName
.Send
End With

Application.ScreenUpdating = True
Set Wb = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub