How do I copy data from excel to a power point slide using virtual basic. The idea is to generate automatic profile slides from excel data. I found some code on how to copy chart objects but not data.
so for example
Name: Yosef
Age: 22
Education: Engineering
Attached picture.
This needs to go onto a slide with a certain font and position. In addition to the attached foto.
Thanks in advance,
Yosef
try
' Create an instance of PowerPoint.
powerpointApplication = _
New Microsoft.Office.Interop.PowerPoint.ApplicationClass()
' Create an instance Excel.
excelApplication = _
New Microsoft.Office.Interop.Excel.ApplicationClass()
' Open the Excel workbook containing the worksheet with the chart data.
excelWorkBook = excelApplication.Workbooks.Open(paramWorkbookPath)
' Get the worksheet that contains the chart.
targetSheet = excelWorkBook.Worksheets("Quarterly Sales")
' Get the ChartObjects collection for the sheet.
ChartObjects = targetSheet.ChartObjects()
' Get the chart to copy.
existingChartObject = ChartObjects.Item("Sales Chart")
' Create a PowerPoint presentation.
pptPresentation = powerpointApplication.Presentations.Add()
' Add a blank slide to the presentation.
pptSlide = _
pptPresentation.Slides.Add(1, pptNS.PpSlideLayout.ppLayoutBlank)
' Copy the chart from the Excel worksheet to the clipboard.
existingChartObject.Copy()
' Paste the chart into the PowerPoint presentation.
shapeRange = pptSlide.Shapes.Paste()
' Position the chart on the slide.
shapeRange.Left = 60
shapeRange.Top = 100
' Save the presentation.
pptPresentation.SaveAs(paramPresentationPath)
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
' Release the PowerPoint slide object.
shapeRange = Nothing
pptSlide = Nothing
' Close and release the Presentation object.
If Not pptPresentation Is Nothing Then
pptPresentation.Close()
pptPresentation = Nothing
End If
' Quit PowerPoint and release the ApplicationClass object.
If Not powerpointApplication Is Nothing Then
powerpointApplication.Quit()
powerpointApplication = Nothing
End If
' Release the Excel objects.
targetSheet = Nothing
ChartObjects = Nothing
existingChartObject = Nothing
' Close and release the Excel Workbook object.
If Not excelWorkBook Is Nothing Then
excelWorkBook.Close(False)
excelWorkBook = Nothing
End If
' Quit Excel and release the ApplicationClass object.
If Not excelApplication Is Nothing Then
excelApplication.Quit()
excelApplication = Nothing
End If
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
End Try


Reply





MultiQuote






|