wolff123456
07-22-2016, 06:57 AM
I am trying to copy an Excel Chart to Word. I have the following script in Excel and it works with Office 2003 for PC and Office Mac 2011. In a later version of Office the chart does not resize when pasted and the token it searches for does not get replaced with the chart as it does in the earlier versions. Here is the script that works but not on later versions of Office. Any help would be greatly appreciated.
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
Set wrd = CreateObject("Word.Application")
wrd.Documents(DocumentName).Activate
wrd.Selection.Find.ClearFormatting
With wrd.Selection.Find
.Text ="insert"& ChartName 'This is the token it is looking for in the Word document and is where the chart should be inserted.
.Replacement.Text =""
.Forward =True
.Wrap =1'wdFindContinue
.Format =False
.MatchCase =False
.MatchWholeWord =False
.MatchWildcards =False
.MatchSoundsLike =False
.MatchAllWordForms =False
.Execute
If.Found =True Then
wrd.Selection.PasteAndFormat Type:=13'wdChartPicture
EndIf
In the earlier versions of Office this script takes the active chart copies it and pastes it into Word by looking for the token and pasting it. The token is replaced by the chart and the chart is resized. In the newer versions the token remains at the bottom of the chart and the chart is not resized.
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
Set wrd = CreateObject("Word.Application")
wrd.Documents(DocumentName).Activate
wrd.Selection.Find.ClearFormatting
With wrd.Selection.Find
.Text ="insert"& ChartName 'This is the token it is looking for in the Word document and is where the chart should be inserted.
.Replacement.Text =""
.Forward =True
.Wrap =1'wdFindContinue
.Format =False
.MatchCase =False
.MatchWholeWord =False
.MatchWildcards =False
.MatchSoundsLike =False
.MatchAllWordForms =False
.Execute
If.Found =True Then
wrd.Selection.PasteAndFormat Type:=13'wdChartPicture
EndIf
In the earlier versions of Office this script takes the active chart copies it and pastes it into Word by looking for the token and pasting it. The token is replaced by the chart and the chart is resized. In the newer versions the token remains at the bottom of the chart and the chart is not resized.