Reputation: 959
I'm trying to copy in a sheet from one workbook to another but because i might already have a previous version of this sheet in my workbook I want to check first if it exists and delete it first before copying. However, keep getting an error when executing remove_sheet (the sheet does get removed though). Any ideas? (BTW It's not the only sheet on the file - so not that issue)
def import_sheet(book_from, book_to ,sheet_to_cpy):
active_wkbk(book_to)
if sheet_to_cpy in all_sheets(True):
remove_sheet(sheet_to_cpy)
active_wkbk(book_from)
copy_sheet(book_to, sheet_to_cpy)
File "blah.py", line 22, in import_sheet
remove_sheet(sheet_to_cpy)
File "27/basic_io.py", line 1348, in remove_sheet
File "27/basic_io.py", line 1215, in active_sheet
NameError: MyTab is not an existing worksheet
Upvotes: 1
Views: 84
Reputation: 1288
This is a bug on our end - we'll fix it as soon as we can!
In the meantime, here's a workaround:
def import_sheet(book_from, book_to, sheet_to_cpy):
active_wkbk(book_to)
if sheet_to_cpy in all_sheets(True):
if sheet_to_cpy == active_sheet():
## avoid bug by manually setting last sheet active
active_sheet(all_sheets()[-1])
remove_sheet(sheet_to_cpy)
active_wkbk(book_from)
copy_sheet(book_to, sheet_to_cpy)
Source: I'm one of the DataNitro developers.
Upvotes: 2