' Define Excel objects, Excel workbook objects, sheet objects
Dim Exlapp,exlworkbook,exlworksheet
' Define File system objects
Dim FSO
' Create Excel
Set Exlapp=CreateObject("Excel.Application")
' Create file Object
Set FSO=CreateObject("Scripting.FileSystemObject")
' Determine if the current path has an Excel file
If FSO. FileExists("C:\test.xlsx")Then
' If an Excel file exists, execute the code
Set Exlworkbook=exlapp. Workbooks.Open("C:\test.xlsx")
Else
' If the Excel file does not exist, execute the code
Set Exlworkbook=exlapp. Workbooks.Add
EndIf
' Create worksheet
Set Exlworksheet=exlapp. Worksheets.add
' Assign a value to a worksheet
Exlworksheet.cells(1,C)="Put it to the reach"
' Save the Excel file, and if you already have the file, save it using the Save method,
' If it is a new Excel file that does not exist, then use the Savaas method to save
If FSO. FileExists("C:\test.xlsx")Then
MsgBox"Excel exists"
Exlworkbook. Save
Else
MsgBox"Excel does not exist"
Exlworkbook. SaveAs("C:\test.xlsx")
EndIf
' Close the working thin
Exlworkbook. Close
' Exit Excel object
Exlapp. Quit
' Release resources
Set Exlapp =Nothing
Set Exlworkbook =Nothing
Set Exlworksheet =Nothing
Set FSO = Nothing
UFT FSO and Excel application