0

I'm trying to automate a report generation and have successfully done it up with OpenPyxl. The report is an excel file with 4 tabs. Currently whenever I open the report after running Openpyxl to get the data - it always opens on the last tab but I would like the file to show me the first tab when I open it. Is there a way to save the file so that it opens up on the first tab instead of the last?

23jnd2
  • 1
  • You try setting the active sheet? https://stackoverflow.com/questions/41556378/openpyxl-set-active-sheet – Amiga500 Jun 03 '21 at 10:13
  • Does this answer your question? [openpyxl Set Active Sheet](https://stackoverflow.com/questions/41556378/openpyxl-set-active-sheet) – MarkSouls Jun 04 '21 at 01:13

1 Answers1

0

If Test.xlsm were a multi worksheet doc that currently had some sheet other than "Sheet1" first visible when opening

import openpyxl

path1 = "C:\\Me\\Docs\\"
file1 = "Test.xlsm"
wb = openpyxl.open(path1 + file1, read_only=False, keep_vba=True)

wb.active = 0  #Note index starts at 0

wb.save(path1+file1)
wb.close()
Amiga500
  • 1,258
  • 1
  • 6
  • 11