Hi,
Hope you can help. My VBA code copies excel charts and then pastes into word doc which has bookmarks. How would I resize the copied chart after it is copied so that it will fit in the area of the doc?
Sub Chart_copy()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdRng As Word.Range
' bail out if no active chart
'If ActiveChart Is Nothing Then
'MsgBox "Select a chart and try again!", vbExclamation, "Export Chart To Word"
'Exit Sub
'End If
' get Word application if it's running
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
On Error Resume Next
If wdApp Is Nothing Then
' word not running so start it and create document
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add
Else
If wdApp.Documents.Count > 0 Then
' get active document
Set wdDoc = wdApp.ActiveDocument
Else
' no active document so create one
Set wdDoc = wdApp.Documents.Add
End If
End If
Set wdRng = wdDoc.Bookmarks("Bookmark1").Range
' copy chart
'ActiveChart.ChartObjects("Chart 2").Copy
Sheets("worksheetname").ChartObjects("Chart 2").Chart.ChartArea.Copy
' paste chart
wdRng.PasteSpecial _
Link:=False, _
DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, _
DisplayAsIcon:=False
End Sub
Hope you can help. My VBA code copies excel charts and then pastes into word doc which has bookmarks. How would I resize the copied chart after it is copied so that it will fit in the area of the doc?
Sub Chart_copy()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdRng As Word.Range
' bail out if no active chart
'If ActiveChart Is Nothing Then
'MsgBox "Select a chart and try again!", vbExclamation, "Export Chart To Word"
'Exit Sub
'End If
' get Word application if it's running
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
On Error Resume Next
If wdApp Is Nothing Then
' word not running so start it and create document
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add
Else
If wdApp.Documents.Count > 0 Then
' get active document
Set wdDoc = wdApp.ActiveDocument
Else
' no active document so create one
Set wdDoc = wdApp.Documents.Add
End If
End If
Set wdRng = wdDoc.Bookmarks("Bookmark1").Range
' copy chart
'ActiveChart.ChartObjects("Chart 2").Copy
Sheets("worksheetname").ChartObjects("Chart 2").Chart.ChartArea.Copy
' paste chart
wdRng.PasteSpecial _
Link:=False, _
DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, _
DisplayAsIcon:=False
End Sub