Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #This is some of the script.
  2. #I've left out irrelevant parts (dialogboxes etc.) just to make it shorter
  3.  
  4. #Import pywin32 and open Excel and selected workbook.
  5. import win32com.client as win32
  6.  
  7. excel = win32.gencache.EnsureDispatch("Excel.Application")
  8. excel.Visible = False
  9.  
  10. wb = excel.Workbooks.Open(wb_path)
  11.  
  12. #Select the 1st worksheet in the workbook
  13. #This is just used for testing
  14. wb.Sheets([1]).Select()
  15.  
  16. #This is the line I can't get to work
  17. ps_prar = wb.ActiveSheet.PageSetup.PrintArea
  18.  
  19. #This is just used to test if I get the print area
  20. print(ps_prar)
  21.  
  22. #This is exporting the selected worksheet to PDF
  23. wb.Sheets([1]).Select()
  24. wb.ActiveSheet.ExportAsFixedFormat(0, pdf_path, Quality = 0, IncludeDocProperties = True, IgnorePrintAreas = False, OpenAfterPublish = True)
  25.  
  26. #This closes the workbook and the Excel-file (although Excel sometimes still exists in Task Manager
  27. wb.Close()
  28. wb = None
  29. excel.Quit()
  30. excel = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement