[VBA] Change size of a pasted chart from Excel into an email

Shewie

New Member
Joined
Jan 18, 2019
Messages
9
Hi,
I'm having a problem with a chart that I'm pasting from an excel sheet to an email: I can't set the size of the chart.
Can you help me please?


VBA Code:
Set oLookApp = GetObject(, "Outlook.Application")
Set ChrtObj = ActiveSheet.ChartObjects(1)
      ChrtObj.Chart.ChartArea.Copy

With oLookItm
        .To = "xyz"
        .CC = "abc"
        .HTMLBody "aaaaa"

Set oWdEditor = .GetInspector.WordEditor

Set oWdRng = oWdEditor.Application.ActiveDocument.Content
      oWdRng.InsertAfter " " & vbNewLine
      oWdRng.Collapse Direction:=wdCollapseEnd

      oWdRng.Paste


I tried to add

.LockAspectRatio =msoFalse
.Height = 1000
.Widht = 1000

But it didn't work.

Thanks a lot!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
After pasting the chart, try adding the following code...

VBA Code:
    With oWdEditor
        With .InlineShapes(.InlineShapes.Count)
            .LockAspectRatio = msoFalse
            .Width = 1000
            .Height = 1000
        End With
    End With

Hope this helps!
 
Upvote 0
After pasting the chart, try adding the following code...

VBA Code:
    With oWdEditor
        With .InlineShapes(.InlineShapes.Count)
            .LockAspectRatio = msoFalse
            .Width = 1000
            .Height = 1000
        End With
    End With

Hope this helps!
WoW!
Thank you so much, it works!

Could you please explain me the logic behind?

Thanks a lot!
 
Upvote 0
You're very welcome, glad I could help.

With regards to the logic, when the chart is added to the document, it's added to the InlineShapes collection. As each one is added to the collection, it's assigned an index number starting with 1. Therefore, we have the following...

oWdEditor.InlineShapes.Count --> returns the number of inline shapes that the document contains

oWdEditor.InlineShapes(oWdEditor.InlineShapes.Count) --> refers to the last inline shape that was copied and pasted into the document

For efficiency, I simply used the With/End With statement to refer to the last inline shape...

VBA Code:
    With oWdEditor
        With .InlineShapes(.InlineShapes.Count)
            .LockAspectRatio = msoFalse
            .Width = 1000
            .Height = 1000
        End With
    End With

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,543
Messages
6,120,123
Members
448,947
Latest member
test111

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