0

I'd like to copy a range from an excel document into a powerpoint slide.

This is my attempt after reading through this documentation :

import win32com.client

powerpoint_object = win32com.client.Dispatch("Powerpoint.Application")
powerpoint_object.visible = True
powerpoint_presentation = powerpoint_object.Presentations.Open("example_powerpoint.pptx")


excel_object = win32com.client.Dispatch("Excel.Application")
excel_object.visible = True
excel_workbook = excel_object.Workbooks.Open(Filename="example_excel.xlsx")
excel_worksheet = excel_workbook.Worksheets("Sheet1")
excel_range = excel_worksheet.Range("A1:L100")
excel_range.Copy()

powerpoint_slide = powerpoint_presentation.Slides.Add(1,12)
powerpoint_slide.Shapes().Paste()

However I get the following error:

com_error: (-2147352567, 'Exception occurred.')
Chris
  • 5,444
  • 16
  • 63
  • 119

1 Answers1

0

Most likely this error is caused by the lack of full file paths. Try replacing "example_powerpoint.pptx" and "example_excel.xlsx" with their full paths.

Xukrao
  • 8,003
  • 5
  • 26
  • 52