resize a pasted Chart in Word from Excel/vba

drom

Well-known Member
Joined
Mar 20, 2005
Messages
543
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Hi and Thanks in advance!
I am inserting a chart from Excel to Word, (works Fine)

VBA Code:
On Error Resume Next:                     Application.ScreenUpdating = False
  Dim wsFilterRp As String:               wsFilterRp = Fx_wShtName(X:=180)
Dim obChart3 As ChartObject:              Set obChart3 = ActiveSheet.ChartObjects("Chart3")
  Dim WordApp As Object:                  Set WordApp = GetObject(, "Word.Application")
  Dim WordDoc As Object
  
  
  If WordApp Is Nothing Then
    Set WordApp = CreateObject("Word.Application")
  End If
    WordApp.Visible = True
    Set WordDoc = WordApp.Documents.Add
    WordDoc.Select
 
  obChart3.Chart.ChartArea.Copy
  Application.Wait Now + TimeValue("00:00:02")
  WordApp.Selection.PasteAndFormat 13

But after I Insert the Excel Chart named "Chart3" in my ActiveSheet

How can I resize this pasted Chart/Picture/Shape ??
  • So that it measures as the width of the Wrod Document, page.

My Pasted Chart/Picture/Image in X times bigger than the Active WordDocument
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi again Drom. U can trial this...
Code:
Dim WidthAvail As Double
'determine width
With WordApp.ActiveDocument.PageSetup
    WidthAvail = .PageWidth - .LeftMargin - .RightMargin - .Gutter
End With
'size shape to sheet
With WordDoc.Shapes(Shapes.Count)
.LockAspectRatio = msoFalse
.Width = WidthAvail
End With
Dave
 
Upvote 0
With WordDoc.Shapes(Shapes.Count) .LockAspectRatio = msoFalse .Width = WidthAvail End With

Hi
My VBA code, does not recognize any shape in my Word document (despite I am iserting a chart from Excel using VBA
When I Use the Inmediate window I get:
VBA Code:
?WordDoc.Shapes.Count
 0 
?WordApp.ActiveDocument.Shapes.Count
 0 
?WordApp.Shapes.Count
Error

So I can't Apply:

VBA Code:
With WordDoc.Shapes(Shapes.Count)
.LockAspectRatio = msoFalse
.Width = WidthAvail
End With

And I need that in order to :
VBA Code:
.LockAspectRatio = msoFalse
etc

Any new help ?
Hi again Drom. U can trial this...
Code:
Dim WidthAvail As Double
'determine width
With WordApp.ActiveDocument.PageSetup
    WidthAvail = .PageWidth - .LeftMargin - .RightMargin - .Gutter
End With
'size shape to sheet
With WordDoc.Shapes(Shapes.Count)
.LockAspectRatio = msoFalse
.Width = WidthAvail
End With
Dave
 
Upvote 0
maybe...
Code:
'size shape to sheet
With WordDoc.InLineShapes(InlineShapes.Count)
.LockAspectRatio = msoFalse
.Width = WidthAvail
End With
Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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