Adding code to a command button

  • Thread starter Thread starter Todd
  • Start date Start date
T

Todd

I am trying to add the following code to a command button
so it will run when the button is pressed. I created the
command button then inserted the code under the "Private
Sub CommanButton1_click () phrase. It returns a compile
error message of "Expected End Sub" when it is run. Is
the wording incorrect on this or is there another
problem? Thanks for the help. The code is below:

Private Sub CommandButton1_Click()
Sub Mail_workbook_Outlook()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "(e-mail address removed)"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

End Sub
 
Hi Todd

haven't really read through each line of your code but removing
Sub Mail_workbook_Outlook()
and one of the
End Sub
lines
might be a starting point.

Cheers
JulieD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top