VBA help for copying Chart from Excel to Word

junkforhr

Board Regular
Joined
Dec 16, 2009
Messages
115
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have found a bit of code ( thanks to whoever orginally wrote it) that will copy a chart from Excel and place it in Word, however I for the life of me cannot work out how to re-size the picture to say 88%. I'll admit I am no expert when it comes to VBA, so I was hoping someone could tweak this code for me:
****************
Sub Customers()
'You will need to select Microsoft Word 12.0 under Tools and then References
Dim wdApp As Word.Application

'Copy Chart
Sheets("Area Data").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Copy

On Error Resume Next
'Try to establish link to open instance of Word
Set wdApp = GetObject(, "Word.Application")

'If this fails, open Word
If wdApp Is Nothing Then
Set wdApp = GetObject("", "Word.Application")
End If
On Error GoTo 0

With wdApp
'Add new document
.Documents.Add
'Make Word visible
.Visible = True
End With
With wdApp.Selection

'Go to end of document and insert paragraph
.PageSetup.Orientation = wdOrientLandscape
.EndKey Unit:=wdStory
.Font.Bold = wdToggle
.Font.Size = 18
.TypeText Text:="Title of Page to go here"
.Font.Size = 10
.TypeParagraph
'Paste Chart
.PasteSpecial , Link:=False, DataType:=14, _
DisplayAsIcon:=False
End With
'Release object variable
Set wdApp = Nothing
End Sub
**********************************

Hopefully someone can help me.

Cheers
Haydn
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Well after much searching on the internet, I have sort of found a solution. Posting here in case someone else will find it useful. This will help me as I have a lot of charts to export and then import into word. My solution, while probably not the best, will be to repeat this code and change the cheet name and chart name. Anyway here is the updated code.
**********
Sub Customers()
'You will need to select Microsoft Word 12.0 under Tools and then References
Dim wdApp As Word.Application

'Copy Chart
Sheets("Area Data").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Copy

On Error Resume Next
'Try to establish link to open instance of Word
Set wdApp = GetObject(, "Word.Application")

'If this fails, open Word
If wdApp Is Nothing Then
Set wdApp = GetObject("", "Word.Application")
End If
On Error GoTo 0

With wdApp
'Add new document
.Documents.Add
'Make Word visible
.Visible = True
End With
With wdApp.Selection

'Go to end of document and insert paragraph
.PageSetup.Orientation = wdOrientLandscape
.EndKey Unit:=wdStory
.Font.Bold = wdToggle
.Font.Size = 18
.TypeText Text:="Title of Page to go here"
.Font.Size = 10
.TypeParagraph
'Paste Chart
.PasteSpecial , Link:=False, DataType:=14, _
DisplayAsIcon:=False
End With
With Selection
.Width = 500
.Height = 500
End With

'Release object variable
Set wdApp = Nothing
End Sub
****************
Cheers
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top