Application of UFT FSO to Excel

Source: Internet
Author: User

' 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.