J
Jim Benet
Please help! I am trying to copy Excel charts (graphs) as pictures into a
Word document. The Excel macro works fine, but the Word macro fails. The
Excel macro merely copies the chart and then calls the Word macro to do the
pasteing. In the word macro, I can paste the chart into the document, but it
pastes it in as an Excel chart. I want to paste it in as a picture.
My Excel macro and 3 versions of my Word macro are below. Version A of
the Word macro works fine, but copies the entire chart. Version B pastes as
a picture, but eliminates all the colors in my chart. Version C doesn’t work
at all.
Can someone suggest a better way to make the macro do what I want it to do?
Thanks, Jim Benet
-----------------------------------------
‘ Excel macro:
Sub Make_Report()
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
‘ Start Word and create an object
With WordApp
.Documents.Open Filename:=Word_Dir & Word_FILE
End With
' Get plot from Excel file
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
' Send to Word
With WordApp
.Application.Run MacroName:="Macro3"
End With
' Kill the object
With WordApp
.ActiveDocument.SaveAs Filename:=WD_Dir & WD_file
End With
WordApp.Quit
Set WordApp = Nothing
End Sub
-------------------------------------------
‘Word Macros:
Sub Macro3() ‘Version A
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Paste
Selection.EndKey unit:=wdStory
Selection.EndKey unit:=wdLine
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
End Sub
Sub Macro3() ‘Version B
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.PasteAndFormat Datatype:=wdPasteEnhancedMetafile
Selection.EndKey unit:=wdStory
Selection.EndKey unit:=wdLine
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
End Sub
Sub Macro3() ‘Version C
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.PasteAndFormat (wdChartPicture)
Selection.EndKey unit:=wdStory
Selection.EndKey unit:=wdLine
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
End Sub
Word document. The Excel macro works fine, but the Word macro fails. The
Excel macro merely copies the chart and then calls the Word macro to do the
pasteing. In the word macro, I can paste the chart into the document, but it
pastes it in as an Excel chart. I want to paste it in as a picture.
My Excel macro and 3 versions of my Word macro are below. Version A of
the Word macro works fine, but copies the entire chart. Version B pastes as
a picture, but eliminates all the colors in my chart. Version C doesn’t work
at all.
Can someone suggest a better way to make the macro do what I want it to do?
Thanks, Jim Benet
-----------------------------------------
‘ Excel macro:
Sub Make_Report()
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
‘ Start Word and create an object
With WordApp
.Documents.Open Filename:=Word_Dir & Word_FILE
End With
' Get plot from Excel file
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
' Send to Word
With WordApp
.Application.Run MacroName:="Macro3"
End With
' Kill the object
With WordApp
.ActiveDocument.SaveAs Filename:=WD_Dir & WD_file
End With
WordApp.Quit
Set WordApp = Nothing
End Sub
-------------------------------------------
‘Word Macros:
Sub Macro3() ‘Version A
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Paste
Selection.EndKey unit:=wdStory
Selection.EndKey unit:=wdLine
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
End Sub
Sub Macro3() ‘Version B
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.PasteAndFormat Datatype:=wdPasteEnhancedMetafile
Selection.EndKey unit:=wdStory
Selection.EndKey unit:=wdLine
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
End Sub
Sub Macro3() ‘Version C
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.PasteAndFormat (wdChartPicture)
Selection.EndKey unit:=wdStory
Selection.EndKey unit:=wdLine
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
End Sub