Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Email with sheet as body

Status
Not open for further replies.

astrevens

Technical User
Aug 8, 2001
36
GB
Plase can someone help.
I need to send the contents of an excel worksheet via email exactly how you do it if you select: file>Send To>Mail Recipient.

Im using excel xp and need to code this in vba. Ive tried the sendmail function but this sends the whole thing.

Many thanks
Andy
 
I havn't got XP but I know you can send 1 sheet by email - look at the VBA help for sendmail - should be one of the optional arguments I'd've thought Rgds
~Geoff~
 
sorry it only says bout the workbook method. im really pullin out me hair here!
 
try typing send worksheet in the help wizard (VBA, not excel) Rgds
~Geoff~
 
sorry mate, nothing there about it. if no one can help me on that perhaps someone could tell me how to open an outlook new mail message, copy the excel sheet and paste onto the mail message and send it?
 
Try the following code, which shoul dsend the active sheet to 'Recipient', which hcan be replaced with a valid email address.

A new workbook is created with just one sheet and mailed. It is then closed without saving.
Code:
Sub MailActiveSheet()
    ActiveSheet.Copy
    With ActiveWorkbook
        .sendmail Recipients:="Recipient"
        .Saved = True
        .Close
    End With
End Sub
A.C.
 
That works ok but if you actually go into xp and select file>send to>mail recipient (not "as attachement"). This actually puts the data into html format then into the body of the email itself.
I can make a new mail message from excel vba but i can't figure out how to get the sheet into the body of the email.
 
Record yourself doing the steps you mention above - then look at the macro that is produced Rgds
~Geoff~
 
tried that also and nothing shows up in the code!!!
 
Have you tried the sendkeys statement?
Its not the most efficient way of doing it and if its run while another programs ontop it wont send the keys to excel without more coding. [pc3]
Adam [glasses]
 
nah, thats too messy. this needs to work on most of the computers in the building!!
I can't beleive microsoft would build in something as useful as this but not let u code with it!!!
someone must know!!!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top