Hello everyone!! Has anyone tried to add a new sheet in excel using python code. I have access to the library "win32com.client". I tried the following code. I comment it down. If anyone has tried in anyother way, I will be happy to accept it. Thank you for your time in correcting me.
import win32com.client
from win32com.client import Dispatch
import os
#file path
file_name = 'C:\\Scratch\\998\\20_calculation\\CASE200.xlsm'
#The win32com function to open Excel
excel = Dispatch('Excel.Application')
excel.Visible = True
#If we want to see it change
#Open the file we want in Excel
workbook = excel.Workbooks.Open(file_name)
#Extract some of the file's components we may need
workBook = excel.ActiveWorkbook
activeSheet = excel.ActiveSheet
sheets = workBook.Sheets
#Add another sheet for example
# i got this code from google
sheets.Add(None, sheets('Sheet3')).Name = 'MySheetx'
I get error here saying
File "C:\Users\allursip\AppData\Local\Temp\gen_py\2.7\00020813-0000-0000-C000-000000000046x0x1x8.py", line 32803, in __call__ ret = self._oleobj_.InvokeTypes(0, LCID, 2, (9, 0), ((12, 1),),Index com_error: (-2147352567, 'Une exception s\x92est produite.', (0, None, None, None, 0, -2147352565), None)