Sizing pasted inlineshape

D

dave.cuthill

I am creating a chart in excel and then pasting it into word as an
inlineshape but the default size is incorrect. How do I size the object
at the time of pasting - ie. does inlineshapes(1) necessarily select
the pasted object or does it select the first inlineshape? How do I
make sure I am resizing the pasted object?

Here is an extraction ...

Set oWordDoc = ActiveDocument
TabCnt = oWordDoc.Tables.Count

Set Rng = ActiveDocument.Tables(1).Range
Rng.Collapse wdCollapseEnd
Rng.InsertAfter "" & vbCrLf
Rng.Collapse wdCollapseEnd
BMName = "BarChart"
ActiveDocument.Bookmarks.Add Name:=BMName, Range:=Rng

other stuff ...

oGraphChart.ChartArea.Copy

Rng.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, Placement _
:=wdInLine, DisplayAsIcon:=False
 
J

Jonathan West

I am creating a chart in excel and then pasting it into word as an
inlineshape but the default size is incorrect. How do I size the object
at the time of pasting - ie. does inlineshapes(1) necessarily select
the pasted object or does it select the first inlineshape? How do I
make sure I am resizing the pasted object?

You do this by assigning a range object variable to the pasted Range, and
then manipulating the first InlineShape object within that range.
Here is an extraction ...

Set oWordDoc = ActiveDocument
TabCnt = oWordDoc.Tables.Count

Set Rng = ActiveDocument.Tables(1).Range
Rng.Collapse wdCollapseEnd
Rng.InsertAfter "" & vbCrLf
Rng.Collapse wdCollapseEnd
BMName = "BarChart"
ActiveDocument.Bookmarks.Add Name:=BMName, Range:=Rng

other stuff ...

oGraphChart.ChartArea.Copy

Rng.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, Placement _
:=wdInLine, DisplayAsIcon:=False

Replace the last line with this

Dim PasteRange as Range
Set PasteRange = Rng.PasteSpecial(Link:=False, DataType:=wdPasteOLEObject, _
Placement:=wdInLine, DisplayAsIcon:=False)

With PasteRange.InlineShapes(1)
'add your code here to manipulate the shape
End With


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
D

dave.cuthill

I am unable to get your suggestion to work. The object is pasted but
any attempts to resize the object do not work.
 
C

Cindy M -WordMVP-

I am creating a chart in excel and then pasting it into word as an
inlineshape but the default size is incorrect. How do I size the object
at the time of pasting - ie. does inlineshapes(1) necessarily select
the pasted object or does it select the first inlineshape? How do I
make sure I am resizing the pasted object?
As I recall, when you paste the selection (or range) always ends up to
the left of the pasted object (actually a field of one sort or another).
So best would be to extend the range (to the end of the paragraph, for
example) then pick up the first inline shape in that range.

Note: Often, it's better to have an Excel chart on a separate page in
Excel, sized to the correct size you need in Word. That's the best way to
avoid distortions and similar problems.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

dave.cuthill

Thanks Cindy extending the range did the trick. I tried resizing the
chart in Excel but it seemed to have no effect on what showed up in
Word.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top