For example, Excel-file contains 'Sheet1' sheet:
How to rename Excel worksheet from VBScript and QTP?
Use the following QTP script, which perform the work using Excel's COM object - "Excel.Application":
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.Open ("c:\Book1.xls")
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Name = "VBScript_Excel"
objWorkbook.SaveAs ("c:\Book1.xls")
objExcel.Quit
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.Open ("c:\Book1.xls")
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Name = "VBScript_Excel"
objWorkbook.SaveAs ("c:\Book1.xls")
objExcel.Quit
The above QTP script renames Excel worksheet:
Summary:
- Excel's COM object ("Excel.Application") allows performing operations on Excel application
- The present visual tutorial explains how to rename Excel sheet from QTP
Related articles:
- QTP VIDEO - How to record QTP script?
- How to read XML file from QTP
- QTP - How to capture tool tip?
- All QTP visual tutorials
Do you like this QTP visual tutorial? Would you like to publish it on your site/blog?
You are free to use/copy/publish all materials on your site/blog.
8 comments:
Hey Dmitri....the way you write scripts for COM objects really fascinates me.... From where do you get the information on the different supported COM objects and their associated methods ? I couldnt find any in the QTP help.
Thanks,
George
@ George,
Try this link
dimitry....
please publish articles on testing the database.
@Anonymous,
"testing the database" is a general topic. Could you specify - which features or scenarious in database testing you would like to get explained?
Hi Dmitry,
You article are wonderful. Please try to publish an article on OTA(Open test architecture) used in Quality center and how to work with it using QTP.How we can automate scripts using QTP and QC (As after some time system gets lock and I can't use QC feature of scheduling if I want automated nightly batch runs)
Hi Dmitry,
You article is wonderful. Please try to publish an article on OTA(Open test architecture) used in Quality center and how to work with it using QTP.How we can automate scripts using QTP and QC (As after some time system gets lock and I can't use QC feature of scheduling if I want automated nightly batch runs)
For execute many actions with excel files and recover corrupted or deleted excel file other types there is-Microsoft Excel file is not in recognizable format,tool is free as far as I know,it has many features,moreover program will allow to avoid such error messages, like: xlsx this file is not in a recognizable format, xlsx file is not in a recognizable format or even this file is not in a recognizable version for Excel,help you to get rid of such messages: this file is not in a recognizable format Microsoft Excel, Microsoft Excel recognizable format and Microsoft Excel file is not in recognizable format,also tool will allow you to recover your files in Microsoft Excel format and avoid errors like: this file is not in a recognizable format xlsx, this file is not in a recognizable format xlsm, Microsoft Excel the file is not in a recognizable format, Microsoft Excel XP the file is not in recognizable format or even Excel file not in a recognizable format recovery.
Hi Motevich,
Can you please explain how can we connect to excel database.As in Data Driven Framework.
Thanks
Nancy
Post a Comment