Hello All,
I have no experience with VBA coding but have researched on forums and have found solutions to my problem but they are not working when combined. I am listing what I am trying to do below.
1- I have multiple worksheets in a workbook and I want to auto-generate graphs for them. For that purpose, I used the following:
================================================================
Define Name Col_A1
=INDIRECT("'"&Shts&"'!A2"):INDEX(INDIRECT("'"&Shts&"'!A2:A65536"),MATCH(2,1/(INDIRECT("'"&Shts&"'!A2:A65536")<>"")))
Define Name Col_B1
=INDIRECT("'"&Shts&"'!B2"):INDEX(INDIRECT("'"&Shts&"'!B2:B65536"),MATCH(2,1/(INDIRECT("'"&Shts&"'!B2:B65536")<>"")))
Define Name Shts
=MID(CELL("filename"),FIND("]",CELL("filename"))+1,255)
Insert a blank graph and update datasource as follows:
Values : ='Filename.xls'!Col_B1
Category (X) axis Labels: ='Filename.xls'!Col_A1
================================================================
This worked fine and I now have my graphs with the relevant data on the various worksheets.
2- Now, I need to pick up these graphs and insert them into a powerpoint presentation. The code I found and am using is as follows:
================================================================
Sub Charts_PPT()
Dim ocht As ChartObject
Dim ws As Worksheet
Dim pptApp As Object
Dim pptPres As Object
Dim pptSld As Object
Set pptApp = CreateObject("PowerPoint.Application")
pptApp.Visible = True
Set pptPres = pptApp.Presentations.Add(msoTrue)
For Each ws In ActiveWorkbook.Worksheets
For Each ocht In ws.ChartObjects
ocht.Copy
Set pptSld = pptPres.Slides.Add(pptPres.Slides.Count + 1, 11)
pptPres.Windows(1).View.GotoSlide (pptSld.SlideIndex)
pptSld.Shapes.Title.TextFrame.TextRange = ws.Name & " " & ocht.Name
With pptSld.Shapes.Paste
.Align 1, True
.Align 4, True
End With
Next ocht
Next ws
End Sub
================================================================
This code worked fine when I was manually creating a graph on each separate worksheet but now that I have used the formulae in point 1 to auto generate the graphs in excel, when I run this code I have the same data in the graphs repeating themselves in powerpoint.
Can anybody please help by letting me know what part of the code in point 2 should I change so that I have the charts from excel moved to powerpoint exactly as they are in the multiple worksheets?
BTW, I have Office 2010.
Thank you so much.
Kind Regards,
Ali Akbar.
Bookmarks