TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: civil.eng on September 13, 2022, 03:28:07 PM

Title: Editing an Excel file
Post by: civil.eng on September 13, 2022, 03:28:07 PM
Hello everyone,
I have a subrutin to open an Excel file and add some changes into it, it works well when the excel file is visible, but changes not saved after closing it by using programmatically :

Code: [Select]
  (setq f "D:\\262.csv")
  (setq excel (vlax-get-or-create-object "Excel.Application"))
  (vla-put-visible excel :vlax-true)
  (setq workbooks (vlax-get-property excel 'workbooks))
  (setq currworkbook (vlax-invoke-method workbooks 'open f))
  (setq xlsheets (vlax-get-property currworkbook "Sheets"))
  (setq xlsht (vlax-get-property xlsheets 'item 1))
  (vlax-put-property xlsht 'name "Points")
  (setq xlrng (vlax-get-property xlsht 'usedrange))
  (setq xlcol (vlax-get-property xlrng 'columns))

  (vl-catch-all-apply
    'vlax-invoke-method
    (list xlcol 'autofit)
  )

  (vlax-invoke-method workbooks 'Close :vlax-true)
  (vlax-release-object workbooks)
  (vlax-invoke-method excel 'Quit)
  (vlax-release-object excel)
)


My aim is to open Excel file in a hidden way then making the changes and finally closing it automatically.
Title: Re: Editing an Excel file
Post by: civil.eng on September 19, 2022, 04:15:32 AM
Any help
Title: Re: Editing an Excel file
Post by: It's Alive! on September 19, 2022, 05:06:10 AM
I didn't see a save, just close and quit.
https://learn.microsoft.com/en-us/office/vba/api/excel.workbook.save
Title: Re: Editing an Excel file
Post by: dexus on September 19, 2022, 05:54:59 AM
When I try it I get a "Too many actual parameters" on the line: "(vlax-invoke-method workbooks 'Close :vlax-true)"

So I can't get the code to work, even when excel is opened.