3

How do I create a new, valid Excel file in Autoit?

Local $sFileName = @ScriptDir & "\Worksheet.xls"
Local $oExcel = _Excel_BookNew($sFileName, 10)

creates an invalid one with 0 Bytes, which I cannot open.

IkeRoyle
  • 457
  • 4
  • 13
HausUkrop
  • 61
  • 5

1 Answers1

6

You first have to open Excel, then create the new book, save the book and finally close Excel again.

#include <Excel.au3>
#include <MsgBoxConstants.au3>

Local $FilePath = @ScriptDir & "\Worksheet.xls"

Local $oExcel = _Excel_Open(False, Default, Default, Default, True)
Local $oBook = _Excel_BookNew($oExcel, 1)
_Excel_BookSaveAs($oBook, $FilePath)
_Excel_Close($oExcel, True)

Source:

https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_Open.htm https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_BookNew.htm https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_BookSave.htm

Tipp:

Just google the commands and interpret the exampels.

IkeRoyle
  • 457
  • 4
  • 13