NigelTufnel
Board Regular
- Joined
- Apr 3, 2008
- Messages
- 53
- Office Version
- 365
- Platform
- Windows
I'm developing an application that pastes a large number of Excel 2007 charts into a Microsoft Word 2007 document (each chart replaces a specific Word bookmark). After pasting each Excel chart into Word, I execute a command to re-size the chart.
I'm having a frustrating time as the macro seems to re-size the chart correctly most of the time. However, there are numerous occasions where the chart does not get resized at all--not even a default re-sizing to the document margins that usually happens when you paste a large chart into a Word by hand.
And here's the kicker--the offending charts seem to size perfectly fine when I manually step through the code.
Has anyone experienced anything like this? Any ideas what I might try? I tried inserting a Excel VBA delay before and after pasting, but that didn't help.
For whatever it's worth, here's a rough cut of my code (dWidth is a variable that represents the desired width of the chart, about 6 inches on the page):
Thanks for any help you can provide me.
I'm having a frustrating time as the macro seems to re-size the chart correctly most of the time. However, there are numerous occasions where the chart does not get resized at all--not even a default re-sizing to the document margins that usually happens when you paste a large chart into a Word by hand.
And here's the kicker--the offending charts seem to size perfectly fine when I manually step through the code.
Has anyone experienced anything like this? Any ideas what I might try? I tried inserting a Excel VBA delay before and after pasting, but that didn't help.
For whatever it's worth, here's a rough cut of my code (dWidth is a variable that represents the desired width of the chart, about 6 inches on the page):
Code:
Sub InsertChart(ByVal sBookMark As String, ByVal sChartType As String, ByVal dWidth As Double)
Sheets(sChartType).ChartArea.Copy
wrdDoc.Bookmarks(sBookMark).Range.Select
wrdApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False
wrdApp.Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
wrdApp.Selection.InlineShapes(1).LockAspectRatio = msoTrue
wrdApp.Selection.InlineShapes(1).Width = Int(dWidth * iPointsPerInch)
End Sub
Thanks for any help you can provide me.
Last edited: