Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I cut and paste a graph from excel into powerpoint through VB CODE

Status
Not open for further replies.

snehakevin

Technical User
Sep 14, 2003
33
SG
I have an application which populates data from acces into a template excel file, which has a graph in it, through VB code. The user copies the graph into a power point slide for his presentation. Can I copy this graph straight into the power point slide with my VB coding?

Can anyone help ?
 
'set project references to PowerPoint and Excel

'create an excel.application object
'create an excel.workbook object
'create an excel.worksheet object
'create an excel.chartobject object
Dim objExcel As Excel.Application
Dim objWork As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim objGraph As Excel.ChartObject

'create a powerpoint.application object
'create a powerpoint.presentation object
Dim objPowerPoint As PowerPoint.Application
Dim objSlides As PowerPoint.Presentation

'open your .xls file
'set it to visible
Set objExcel = New Excel.Application
Set objWork = objExcel.Workbooks.Open (...file path)
objExcel.Visible = True

'set your sheet object to sheet number and activate
Set objSheet = objWork.Worksheets(whatever sheet #)
objSheet.Activate

'set your chart object
Set objGraph = objSheet.ChartObjects(whatever object #)

'copy chart
objGraph.CopyPicture Appearance:=xlScreen, Format:=xlBitmap

'open your .ppt file
Set objPowerPoint = New PowerPoint.Application

'set it to visible
objPowerPoint.Visible = msoTrue

'set the right slide and paste
Set objSlides = objPowerPoint.Presentations.Open(file path)
objSlides.Slides(1).Shapes.Paste.Select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top