Hello all
If possible, help from the Excel experts
I have an excel file that contains several worksheets
I want to separate each worksheet into a separate external excel file
I have a code that works fine as in the video
I would like to write it on Python Script
Thank you
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
myfilepath = IN[0]
imagePath = IN[1]
#Assign your output to the OUT variable.
OUT = 0
import clr
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel
# Instantiate the Excel Application
ex = Excel.ApplicationClass()
# Make it Visiable for us all to see
ex.Visible = True
# Disable Alerts - Errors Ignore them, they're probably not important
ex.DisplayAlerts = False
# Create a new Workbook = Spreadsheet file
workbook = ex.Workbooks.Open(myfilepath)
#Create a new Worksheet within our new Workbook
worksheet = workbook.Worksheets[1] # Arrays of Object Start 1 in the MS Office World
worksheet.Copy Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & .Name & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
OUT =myfilepath, dir(worksheet)
code vba excel
Sub SaveAsPDFall()
Dim ws As Worksheet
Dim xPath As String
Dim SH As Worksheet
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Worksheets
With ws
.Copy
Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & .Name & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
Application.ActiveWorkbook.Close False
End With
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
```[Processing: test.rar...]()
[Processing: test.xlsm...]()
[Processing: test.rar...]()
[Processing: test.rar...]()
![wwq|689x386](upload://wHJPsq7sdf5GVpOmR8foqL3CoiE.gif)