copy from worksheet and paste to email body with formatting

DonAndress

Active Member
Joined
Sep 25, 2011
Messages
365
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,

I am trying to get a better copy/paste method. Generally I use Ron de Bruin's code (Mail Range or Selection).
But from my worksheet I am copying a pivot table and I'd like to paste it into email body with all formats, including shading and borders, as you usually do with ctrl+C -> ctrl+V.

So when copying manually, either to other excel sheet, or to outlook email body, all formatting is kept. When I use the below code, shading and borders are lost.

May I ask for a hint on how to keep all of it?

There is no point of me quoting here all Ron's code, I will just paste only this part of code which is responsible for pasting into new file:
VBA Code:
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
    .Cells(1).PasteSpecial Paste:=8
    .Cells(1).PasteSpecial xlPasteValues, , False, False
    .Cells(1).PasteSpecial xlPasteFormats, , False, False
    .Cells(1).PasteSpecial xlPasteAllUsingSourceTheme, , False, False     'sorry, I added this line as a test, doesn't work
    .Cells(1).Select
    Application.CutCopyMode = False
    On Error Resume Next
    .DrawingObjects.Visible = True
    .DrawingObjects.Delete
    On Error GoTo 0
End With
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try adopting the following code...

VBA Code:
    ThisWorkbook.Worksheets("Sheet1").PivotTables("PivotTable1").TableRange2.Copy
   
    With mi
        .Display
        .To = "..."
        .Subject = "..."
        With .GetInspector.WordEditor
            .Application.Selection.EndKey Unit:=6 'wdStory
            .Application.Selection.TypeParagraph
            .Application.Selection.TypeParagraph
            .Application.Selection.Paste
        End With
        '.Send
    End With
   
    Application.CutCopyMode = False

...where the variable mi represents a MailItem.

Hope this helps!
 
Upvote 0
When I run the code, here's what I get...

Excel Worksheet

don.xlsm
ABCDEFGHI
1Region(All)
2
3Row LabelsSum of Sales
4Amy$ 112,624
5Bob$ 203,736
6Chuck$ 86,464
7Doug$ 100,768
8Grand Total$ 503,592
9
10
Pivot


Outlook Email


2023-08-18_16-54-01.jpg


Can you post the exact code that you're using to copy and paste?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
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