borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Outlook Express)Next Topic (Remove Add-In) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : PLEASE HELP: Email Excel worksheet in body, not as an attachment
Poster Message
karsch
Level: Guest


icon PLEASE HELP: Email Excel worksheet in body, not as an attachment

Hi,

I know how to send an Excel worksheet as an attachment, but does anyone know how to send the worksheet in the body of the email? If you do File -> Send To -> Mail Recipient, you'll be able to send the worksheet in the message body, but I couldn't seem to find a way to do this in VB. Any help would be greatly appreciated. Thank you.

16-06-2003 at 09:11 PM
| Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: PLEASE HELP: Email Excel worksheet in body, not as an attachment

I cannot duplicate such a mail, but if you'd like to e-mail me an example I would be happy to take a look at it...

____________________________
Eggheads unite! You have nothing to lose but your yolks.

17-06-2003 at 05:26 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: PLEASE HELP: Email Excel worksheet in body, not as an attachment

Hi Karsch

I have done it.


Private Sub Command1_Click()

    Dim olapp As Outlook.Application
    Dim olmsg As Outlook.MailItem
    Dim xlapp As Excel.Application
    
    Dim html As String
    Dim singlechar As String
    Dim ff As Integer
    
    ff = FreeFile
    Set xlapp = New Excel.Application
    xlapp.Workbooks.Open "c:book1.xls"
    xlapp.ActiveWorkbook.SaveAs "c:book1.htm", XlFileFormat.xlHtml
    xlapp.Quit
    Set xlapp = Nothing
    
    Open "c:book1.htm" For Binary As #ff
    Do While Not EOF(ff)
        singlechar = Input(1, #1)
        html = html & singlechar
    Loop
    Close #ff
    
    Set olapp = New Outlook.Application
    Set olmsg = olapp.CreateItem(olMailItem)

    olmsg.Subject = "HTML Test"
    olmsg.HTMLBody = html
    
    olmsg.Recipients.Add "steven.willetts@ntlworld.com"
    olmsg.Send

End Sub



        Steve

Also don't forget to include the outlook and excel references in your project.



only works with outlook 2000 or greater !!!

[Edited by steve_w on 14-07-2003 at 02:23 PM GMT]

17-06-2003 at 10:48 PM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: PLEASE HELP: Email Excel worksheet in body, not as an attachment

Had an e-mail off Karsch to say that he had found a solution.

It does the same as mine but its coded a bit better and has more options, for anyone who is interested heres the link.

http://www.dicks-clicks.com/excel/olSending.htm



By the way its not a porn site

[Edited by steve_w on 18-06-2003 at 03:21 PM GMT]

18-06-2003 at 02:35 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : PLEASE HELP: Email Excel worksheet in body, not as an attachment
Previous Topic (Outlook Express)Next Topic (Remove Add-In) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder