Paste into body of email Vba

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,129
Office Version
  1. 365
Platform
  1. Windows
HI,

Working on a macro and need help. Just trying to paste this range below into the body of an email in outlook.

I already copied range opened email with vba. I just don't know how to paste this below into body of email. As I can not record it see the outcome.


Code:
Range("B4:H11").Copy

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Don't know about pasting into the body of an email but if you look here you'll find code to add a range, as HTML, to the body of an email.
 
Upvote 0
Hi thanks for the reply. I am working on something that opens my sheet then opens outlook. Which i did already. I just need to take this below from the activesheet all the time and put it into the body of email. I don't think it needs to paste maybe a different way?

Excel 2010 32 bit
[Table="width:, class:head"][tr=bgcolor:#888888][th] [/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#888888]
2
[/td][td]
Cost​
[/td][td]
[/td][td]
Cost to Date​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#888888]
3
[/td][td]
$ 50.00​
[/td][td]
[/td][td]
$ 50.00​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#888888]
4
[/td][td]
$ 100.00​
[/td][td]
[/td][td]
$ 100.00​
[/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet1[/td][/tr][/table]


[TABLE="class: grid"]
[TR]
[TD][/TD]
[/TR]
[/TABLE]

i am using B2 range to D4 better example
 
Last edited:
Upvote 0
Hi thanks for the reply. I am working on something that opens my sheet then opens outlook. Which i did already. I just need to take this below from the activesheet all the time and put it into the body of email. I don't think it needs to paste maybe a different way?

Excel 2010 32 bit
[Table="width:, class:head"][tr=bgcolor:#888888][th] [/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#888888]
2
[/td][td]
Cost​
[/td][td]
[/td][td]
Cost to Date​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#888888]
3
[/td][td]
$ 50.00​
[/td][td]
[/td][td]
$ 50.00​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#888888]
4
[/td][td]
$ 100.00​
[/td][td]
[/td][td]
$ 100.00​
[/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet1[/td][/tr][/table]


[TABLE="class: grid"]
[TR]
[TD][/TD]
[/TR]
[/TABLE]

i am using B2 range to D4 better example

Wait could i just add into my code below
objMail
.HTLMBody = fncRangeToHtml("Sheet1", "B2:D4") ?
 
Upvote 0
Can't really tell without seeing your current code.:)
 
Upvote 0
So this is what I have already. For some reason I cant run it now to test it. It says "Compile Errror Expected Function or Variable" every time I run it. So I couldn't test this either -->
Code:
[LEFT][COLOR=#222222][FONT=Verdana] .HTLMBody = fncRangeToHtml("Sheet1", "B2:D4") 
[/FONT][/COLOR][/LEFT]

So below is mostly what I need it to do plus copy that range and put into body. The excel file will always be open and the tab name is Sheet1.


Code:
Sub Run780()
    With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    
    Emails = "frank.com;"
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    With OutMail
        .Display
    End With
    Signature = OutMail.HTMLBody
    With OutMail
        .To = Emails
        .Cc = "frank.com;"
        .Subject = "Numbers"
        .HTLMBody = fncRangeToHtml("Sheet1", "B2:D4") '-- Didnt test this part yet cause it gives a compile error--'
        .HTMLBody = Signature
    End With
    
    With Application
        .DisplayAlerts = True
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    
    Set OutMail = Nothing
    Set OutApp = Nothing
    
    End Sub
 
Upvote 0
I think I figured out the compile error. I have another sub with the a name in this code. Will fix it tomorrow and test this again. Not sure if that HTLMBody will work well see
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top