Share via

Attach workbook then send it

Anonymous
2011-07-05T22:06:43+00:00

When I run the code below it will take the workbook that is currently open and attach it to an email.  I would like it to also send the email to a specific address like ******@aol.com but I am not sure how to do that.  Do you know how?

Application.Dialogs(xlDialogSendMail).Show

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2011-07-05T22:18:55+00:00

Like this:

Application.Dialogs(xlDialogSendMail).Show Arg1:="myemailaddress"

where myemailaddress is the e-mail address of the recipient. You can also specify the subject:

Application.Dialogs(xlDialogSendMail).Show Arg1:="myemailaddress", Arg2:="Monthly report"

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2011-07-06T06:03:31+00:00

The dialog creates an e-mail but doesn't send it. You could use

ActiveWorkbook.SendMail "myemailaddress", "Monthly Report"

but you'll still run into Outlook security if Outlook is your default e-mail program, and have to allow the message to be sent.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2011-07-06T05:58:52+00:00

The particular function does not allow for the message to be automatically sent - merely displayed. If you want to send it, via Outlook, then try the following instead. Outlook must be configured to send mail immediately or it goes to the Outbox.

Sub SendMyWorkBook()

Dim olApp As Object

Dim olMail As Object

Dim strFileName As String

Dim bStarted As Boolean

ActiveWorkbook.Save

strFileName = ActiveWorkbook.FullName

Set olApp = GetObject(, "Outlook.Application")

If Err <> 0 Then

    Set olApp = CreateObject("Outlook.Application")

    bStarted = True

End If

Set olMail = olApp.CreateItem(0)

With olMail

   .To = "someone AT somewhere.com" 'email address

    '.CC = "someoneelse AT somewhere.com"

    '.BCC = "someoneelse AT somewhere.com"

    .Subject = "Monthly Report" 'Message subject

    .Body = "Report updated " & Format(Date, "d MMMM yyyy") 'message body

    .Attachments.Add strFileName

    .Send

End With

If bStarted Then

    olApp.Quit

End If

'Clean up

Set olMail = Nothing

Set olApp = Nothing

End Sub

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2011-07-06T03:37:22+00:00

    Thanks for the help.  This is great.  For some reason the message still is not sending.  Any thoughts?

    Was this answer helpful?

    0 comments No comments