copy excel chart to word - format problem

S

Samirkc

Dear all,
I am trying to paste excel chart to word (as picture) using VBA. I have one
chart, I change the country name and the year and the chart changes. I then
copy the chart to a Word file (all using Macro). I want to paste chart, one
after another in two columns. The first chart pastes well but (it fits to the
page format), however, the subsequent charts are bigger and do not fit.
Please help. The following is the macro that I use.

Sub graph_20_65_for()
z = "graphs"

Sub Exporter_graph()

' Tools ... References ... Word

Dim MyWord As Word.Application
Dim MyDoc As Word.Document
Dim MyExcel As Excel.Workbook
Dim MyPath, exlMyFileName, wrdMyFileName As String
Dim MyBox
z = "graphs"
MyPath = ActiveWorkbook.Path
exlMyFileName = ActiveWorkbook.Name


Set MyWord = GetObject(, "Word.Application")
Set MyExcel = GetObject(MyPath & "\" & exlMyFileName)
Set MyDoc = MyWord.Documents("graph_projection.doc")
Set MyDoc = MyWord.ActiveDocument

For yr = 1 To 6
MyExcel.Sheets(z).Range("b2").Value = 2000 + 10 * (yr - 1)

MyExcel.ActiveSheet.ChartObjects("Chart 9").Activate
ActiveChart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture


MyWord.Visible = True

'Copying and pasting

MyDoc.ActiveWindow.Selection.Collapse Direction:=wdCollapseEnd

MyWord.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False


MyExcel.Sheets(z).Range("b2").Activate

Next yr


Set MyWord = Nothing
Set MyExcel = Nothing
Set MyDoc = Nothing


End Sub
For n_country = 1 To 120
Sheets(z).Range("a2").Value = _
Sheets(z).Range("a15").Offset(n_country - 1, 0).Value

ind_baseline = Sheets("data_edu_prop").Range("n26").Value
If ind_baseline = 1 Then GoTo samir:

d = Sheets(z).Range("b15").Offset(n_country - 1, 0).Value


Sheets(z).ChartObjects("Chart 9").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = -d
.MaximumScale = d
End With

Call Exporter_graph

samir:
Next n_country
End Sub
 

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