How to create a New Microsoft Excel Worksheet file

How to create a New Microsoft Excel Worksheet file

m09366023695
Enthusiast Enthusiast
387 Views
1 Reply
Message 1 of 2

How to create a New Microsoft Excel Worksheet file

m09366023695
Enthusiast
Enthusiast

I want to create a New Microsoft Excel Worksheet file.

 

Call createFile("c:\myproject\file.xlsx")

 

 

Function createFile(path)

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
If FileExists(path) Then


Else

Set Fileout = fso.CreateTextFile(path, True, True)
Fileout.Write "your string goes 54545645464here"
Fileout.Close
End If


End Function

 

but it create file but I cannot open it.

0 Likes
388 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

You cannot assume an file for a specific application (*.xls/*.xlsx file of Excel application) is a plain text file. Theoretically, only Excel (and some Excel compatible apps) can generate/save a *.xls/*.xlsx file. 

 

However, Excel can open and save data from/to many other formats. In your case, depending on the purpose of using the AutoCAD in the Excel, you can choose either use COM automation to run Excel to open a new XLS/XLSX file and send data to it. But if you do not care to format the data in the worksheet for presenting purpose and only use it for simple data storage, you can simply save the data as CSV file (a plain text file with "," as delimiter. Excel can happily read/save CSV file. Better yet, with CSV data format, in your Acad VBA code, you do not need to run Excel at all.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes