Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

excel file separate each worksheet into a separate external excel file

0 REPLIES 0
Reply
Message 1 of 1
hosneyalaa
242 Views, 0 Replies

excel file separate each worksheet into a separate external excel file

Hello all
If possible, help from the Excel vlisp 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 vlisp 
Thank you

(defun c:excel_Copy( / excel)
  
(setq excel (vlax-create-object "Excel.Application"))
  
(setq workbooks (vlax-get excel 'workbooks))
  
  (setq fname	(getfiled "Select Excel File:" (getvar "dwgprefix") "XLSX;XLS" 4))
  
(vlax-invoke-method workbooks 'Open fname)
  
(setq activeWorkbook (vlax-get Excel 'ActiveWorkbook))
(setq sheets (vlax-get activeWorkbook 'WorkSheets))
(setq i 0)
(vlax-for sh sheets(setq i (1+ i) sheet_names (cons (cons (vlax-get sh 'Name) i) sheet_names)))
  
(setq sheet1_index (cdr (assoc "1" sheet_names)))

  
(setq sheet1 (vlax-get-property sheets 'Item sheet1_index))

  
(vlax-invoke-method sheet1 'Copy (vlax-invoke-method activeWorkbook 'SaveAs "C:\\Users\\alaahossine\\Desktop\\000\\t000test" FileFormat:=xlOpenXMLWorkbookMacroEnabled))

)

 

 

 

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

wwq.gif

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta