amt1906
amt1906

Reputation: 75

Visible property of Power point application in win32com under python is not working when set to false

The visible property of Powerpoint application in the win32com package under python is not working when set to 'False'. It was working when the visible property was set to true and the pptx gets opened once the given piece of code executes. I don't want the PPT to be opened. Could you please suggest some corrections in the given code. I was getting the below error when I executed the below piece of code.

ExcelApp = win32com.client.Dispatch("Excel.Application")
ExcelApp.Visible = False
workbook = ExcelApp.Workbooks.open(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\PerformanceReportMetrics.xlsx')
worksheet = workbook.Worksheets("Summary")
excelrange = worksheet.Range("A1:R20")


PptApp = win32com.client.Dispatch("Powerpoint.Application")
PptApp.Visible = False
z = excelrange.Copy()

PPtPresentation = PptApp.Presentations.Open(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\Performance Reports.pptx')
pptSlide = PPtPresentation.Slides.Add(1,11)
title = pptSlide.Shapes.Title
title.TextFrame.TextRange.Text = 'Metrics Summary'
pptSlide.Shapes.PasteSpecial(z)
PPtPresentation.SaveAs(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\Performance2.pptx',1)
workbook.Save()
workbook.Close(True)

Error messages

PptApp.Visible = False, self.oleobj.Invoke(entry.dispid, 0, invoke_type, 0, value) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft PowerPoint', 'Application.Visible : Invalid request. Hiding the application window is not allowed.', '', 0, -2147188160), None)

Upvotes: 2

Views: 3149

Answers (1)

ZhaoComing
ZhaoComing

Reputation: 51

Add

WithWindow=False 

in open statement. like this:

PPtPresentation = PptApp.Presentations.Open(r'C:\demo.pptx', WithWindow=False)

Upvotes: 5

Related Questions