Select multiple charts to be copied

bg18461

New Member
Joined
Jan 17, 2008
Messages
41
I am trying to select 2 charts on my worksheet simultaneously so I can copy them into word via vba. Manually its no problem, select 2nd chart while pressing the ctrl button, but how do you do this programmatically via vba.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi bg18461


As you may know one usually avoids selecting objects when working in vba. It brings no advantage and makes the code less efficient and more difficult to read.

This is an example that copies 2 charts from sheet1 to a word document. Try this and adapt it to your case:

Code:
Sub CopyToWord()
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim wbk As Workbook
 
Set wbk = ActiveWorkbook
 
Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Open("c:\tmp\doc1.docx")
 
wbk.Worksheets("Sheet1").Shapes.Range(Array("Chart 1", "Chart 2")).Group.Copy
wordDoc.Content.Paste
 
wordDoc.Save
wordDoc.Close
wordApp.Quit
 
End Sub

Remark: don't forget to enable the word library in Tools>References

Hope this helps
 
Upvote 0
P. S. I assumed that the word document already exists. If that's not the case isntead of .Documents.Open you'll have to use .Documents.Add
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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