Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 320
amt1906 Avatar asked Dec 31 '25 03:12

amt1906


1 Answers

Add

WithWindow=False 

in open statement. like this:

PPtPresentation = PptApp.Presentations.Open(r'C:\demo.pptx', WithWindow=False)
like image 105
ZhaoComing Avatar answered Jan 02 '26 18:01

ZhaoComing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!