QTP - How to rename Excel worksheet

QTP - How to rename Excel worksheet

The present QTP tutorial shows simple recipe how to rename Excel worksheet from QuickTest Professional.

For example, Excel-file contains 'Sheet1' sheet:
Initial worksheet

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

The above QTP script renames Excel worksheet:
Renamed 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:


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:

George said...

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

Dmitry Motevich said...

@ George,
Try this link

Anonymous said...

dimitry....
please publish articles on testing the database.

Dmitry Motevich said...

@Anonymous,
"testing the database" is a general topic. Could you specify - which features or scenarious in database testing you would like to get explained?

Anonymous said...

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)

Anonymous said...

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)

Alex said...

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.

Nancy said...

Hi Motevich,

Can you please explain how can we connect to excel database.As in Data Driven Framework.
Thanks
Nancy