QTP Script 1 - How to launch a QTP
application, open a new test and close QTP through a script.
This below code launches QuickTest Professional.
1. I made a folder with the name 'qtp' under c:\
2. I wrote the below code in a notepad file and saved it as
launch.vbs under c:\qtp
3. Now I went to command prompt (Start->All
Programs->Accessories->Command Prompt). On the C:\> prompt I wrote:
C:\>cd qtp
4. The command prompt now was:
C:\qtp>
5. Then I wrote file name (launch.vbs) and hit enter. It launched
QTP Application.

CreateObject:
We first create an instance of an object and its reference
is stored in a vbscript variable (like first two lines of the code below). Then
we can access methods and properties of an object using variable.method_name
and variable.property_name
For Example to open a word application and to get its
version, use the below code. Write it in a notepad, save it as .vbs file and
run it.
Dim WordApp
Set WordApp = CreateObject("word.application")
WordApp.Application.Visible = True
x=WordApp.Application.Version
msgbox x
QTP Script 2 - How to get data from Excel into QTP without
importing the Excel.

For this code make sure that you have excel file Book1.xls
under c:\ and write some dummy values in its first few cells.
Write the whole above code in a new test in QTP and run it.
This is an excellent source of excel object model. You will
simply love this.
Excel Object Model
Just download the file (vbaxl11.exe) from here and when you
install it, there will be a file vbaxl10.chm in the installed location.
QTP Script 3 - How to launch QTP, open a test, run it,
display results and close QTP.

Lets first of all record a simple test and then we will run
this test through a automated script.
1. Open QTP and a new blank test.
2. Click on Record. Record and Run Settings window will
open. GO to Windows Applications tab and choose the first option "Record
and run test on any open Windows-based application". Click Ok.
3. Go to Start-> All Programs-> QuickTest
Professional->Sample Application-> Flight.
4. Login window opens.
5. Enter "sach" as Agent Name and
"mercury" as Password. Click Ok.
6. Flight Reservation window opens. Go to File->Exit.
7. Save the Test. (I saved the test as Test3 at C:\Program
Files\Mercury Interactive\QuickTest Professional\Tests\Test3)
QTP Script 4 - How to bring data from a text file into QTP
data table.

Write the below code in a new test in qtp and run it.
Write the below code in a notepad, save it with .vbs
extention and run it from command prompt.
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 5 - How to import excel into datatable in QTP.

QTP Data Table Basics
Reading
values From Data Table
Writing Values To Data Table
Accessing Data Table through scripts
Multiple Choice Questions on Data Table
Table Checkpoints Multiple Choice Questions
Data Table Menu Shortcut Keys
QTP Script 6 - How to pass output parameter's value of one
test to input parameter of another test.
' Open a new test and go to File->Settings, Parameters
tab.
' Define an input parameter "inpar" as string with
a default value of "Dvalue".
' Define one output parameter "outpar" as string.
' write the below lines of code in the Expert View of the
test and save it as Test-p1 under C:\Program Files\Mercury
Interactive\QuickTest Professional\Tests.
Testargs("outpar")=Testargs("inpar")
msgbox TestArgs("outpar")
' Open a new test and go to File->Settings, Parameters
tab.
' Define an input parameter "inpar2" as string
with a default value of "Dvalue2".
' write the below line of code in the Expert View of the
test and save it as Test-p2
' under C:\Program Files\Mercury Interactive\QuickTest
Professional\Tests.
msgbox testargs("inpar2")
' This below code is opening a test called Test-p1, setting
its first input parameter to "Hello World" and running the test.
Test-p1 is just assigning the input parameter to the output parameter when it
is run and that output parameter is displayed in the messagebox. After that the
value of the ouput parameter of the Test-p1 is being assigned to
"val" so that it can be passed as input parameter to Test-p2. Test-p2
is just displaying the value of inpar2 which it got from Test-p1.

QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 7 - How to copy data from Excel sheet to a Text
file?

How to copy data from Excel sheet to a Text file?
You can manipulate the below script to meet your
requirements.
A text file sample.txt exists in the C:\ drive. Sample.txt
is opened in append mode which is 8. We use writeline to write each line into
text file.
An Excel file Book1.xls exists in C:\ drive and it has some
text in columns and rows of its sheet1. In the For loop we are transferring
data from first three rows of excel sheet to a text file called sample.txt.
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 8 - How to count and get the path & name of
all the object repositories associated with an action?

'How to count and get the path & name of all the object
repositories associated with an action ?
BEFORE YOU TRY TO RUN THIS CODE, YOU SHOULD KNOW HOW TO
CREATE A SHARED OBJECT REPOSITORY.
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 9 - How to move data from a text file to excel
sheet.

'How to move data from a text file to excel sheet.
You can manipulate the below script to meet your
requirements.
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 10 - How to get all files and folders within a
given folder?
How to get all files and folders within a given folder?
'The following VBScript code will recursively loop through
all the files and sub folders within a given folder and store their value in a
variable.

QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 12 - How to get the count and name of all the
Recovery Scenarios associated with the test?

QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function Libraries
QTP GetTOProperties,
GetROProperty
Search more on QTP here
QTP Script 16 - How to count total number of links on a web
page?
Counting Total Links on a web page
Make sure www.google.com is open and write the below code in
a new test and run it. It may show different results than mine, depending on
the links on Google page at that time. I have shown my answer below.
Set Des_Obj = Description.Create
Des_Obj("micclass").Value = "Link"
Set link_col =
Browser("name:=Google").Page("title:=Google").ChildObjects(Des_Obj)
msgbox link_col.count
'You must use the Description object to create the
programmatic description for the ChildObjects description argument. You cannot
enter the programmatic description directly into the argument using the property:=value
syntax.
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 17 - How to get link names and URLs for all the
links on a web page?
For getting link names and URLs for each of the links it
counted in Previous Script [Counting Total Links on a Web page]
If you have not seen the previous script, for your
information you have to open www.google.com and write the below script in a new
test and run it. It will show the link names and URLs in a messagebox one by
one. You can move the results directly to the excel file also (take help from
QTP Script 9 and 15).
Set Des_Obj = Description.Create
Des_Obj("micclass").Value = "Link"
Set link_col =
Browser("name:=Google").Page("title:=Google").ChildObjects(Des_Obj)
a= link_col.count
For i=0 to a-1
tag = link_col(i).GetROProperty("name")
href = link_col(i).GetROProperty("url")
msgbox tag &" " & href
Next
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 24 - How to run multiple tests in QuickTest
professional (QTP) ?
'This is just one of the ways of doing this. I created three
tests tr1, tr2 and tr3. In the Expert View of tr1 I wrote just one line -
msgbox ("Test 1"), in the Expert View of tr2 - msgbox ("Test
2") and in the Expert View of tr3 - msgbox ("Test 3").
'Write the below code in a text file and Save it with .vbs
extension and run it.
Dim App
Set App = CreateObject("QuickTest.Application")
App.Launch
App.Visible = True
Dim QTP_Tests(3)
QTP_Tests(1) = "C:\Program Files\HP\QuickTest
Professional\Tests\tr1"
QTP_Tests(2) = "C:\Program Files\HP\QuickTest
Professional\Tests\tr2"
QTP_Tests(3) = "C:\Program Files\HP\QuickTest
Professional\Tests\tr3"
'Creating the RunResultsOptions object. It is a collection
of properties that indicate preferences for the run results. E.g.
ResultsLocation property as used below which tells the path in which the run
results will be stored.
Set res_obj =
CreateObject("QuickTest.RunResultsOptions")
For i = 1 to UBound (QTP_Tests)
App.Open QTP_Tests(i), True
Set QTP_Test = App.Test
res_obj.ResultsLocation = QTP_Tests(i) &
"\Res1" ' Set the results location
'Using the Run method. Run Method runs the open test or
business component and creates results in the specified file or Quality Center path. A Boolean value - true or
false can be set. Indicates whether the Test.Run statement waits until the end
of the run before performing the next statement in the automation script.
Default=True.
QTP_Test.Run res_obj, True
QTP_Test.Close
Next
App.Quit
Set res_obj = nothing
Set QTP_Test = nothing
Set App = nothing
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
QTP Script 26 - How to run all tests in a specific folder in
QuickTest professional (QTP)?
'For this script I created three tests tr1, tr2 and tr3. In
the Expert View of tr1 I wrote just one line - msgbox ("Test 1"), in
the Expert View of tr2 - msgbox ("Test 2") and in the Expert View of
tr3 - msgbox ("Test 3"). I went to C:\Program Files\HP\QuickTest
Professional and created a folder named "tests1". I then moved
folders tr1, tr2 and tr3 which belong to tests I created from C:\Program
Files\HP\QuickTest Professional\Tests to tests1 folder (C:\Program
Files\HP\QuickTest Professional\tests1) which I created above and gave the same
path in the script. Now this code will run all the tests (3 in our case) in
that folder.
Dim qtp_app
Dim file_sys
Dim Dir
Dim test_collection
Set qtp_app =
CreateObject("QuickTest.Application")
qtp_app.Launch
qtp_app.Visible = True
' The file_systemObject object is used to access the file
system on the server. This object can manipulate files, folders, and directory
paths.
Set file_sys =
CreateObject("Scripting.filesystemObject")
'GetFolder: Returns a Folder object for a specified path
Set Dir = file_sys.GetFolder( "C:\Program
Files\HP\QuickTest Professional\tests1" )
Set test_collection = Dir.SubFolders
'RunResultsOptions:A collection of properties that indicate
preferences for the run results.
Set qtResultsObj =
CreateObject("QuickTest.RunResultsOptions")
For each t_folder in test_collection
qtp_app. Open t_folder.Path, True, False
'Setting the location for the run results
qtResultsObj.ResultsLocation = t_folder.Path &
"\Res1" ' Set the results location
' Execute the test. Instruct QuickTest Professional to wait
for the test to finish executing.
qtp_app.Test.Run qtResultsObj, True
qtp_app.Test.Close
Next
qtp_app.Quit
Set test_collection = Nothing
Set Dir = Nothing
Set file_sys = Nothing
Set qtp_app = Nothing
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
XMLUtil - How to compare two XML files.
XMLUtil-7: How to compare two XML files.
Below are the two xml files used. There is very small
difference between these two XML files. Just try to understand how Compare
method gives results. You can always change/modify the code according to your
requirements.
XML file-1 - env.xml
XML file-2 - env1.xml
Using different XML files:
Set doc=XMLUtil.CreateXML
doc.LoadFile "C:\ENV.xml"
Set docx=XMLUtil.CreateXML
docx.LoadFile "C:\ENV1.xml"
res =
docx.Compare(doc,resultDoc,micXMLValues+micXMLCDataSections)
msgbox resultDoc
if res = 1 then
msgbox "Documents match :)"
else
msgbox "do not match "
end if
Results of running the above code:
Using same XML files:
Set doc=XMLUtil.CreateXML
doc.LoadFile "C:\ENV.xml"
Set docx=XMLUtil.CreateXML
docx.LoadFile "C:\ENV.xml"
res = docx.Compare(doc,resultDoc,micXMLValues+micXMLCDataSections)
msgbox resultDoc
if res = 1 then
msgbox "Documents match :)"
else
msgbox "do not match "
end if
Results of running the above code:
Compare Method
XMLData.Compare(XMLDocument, ResultXMLDocument [, Filter])
XMLDocument: The XML document object that you want to
compare to this XMLData object.
ResultXMLDocument: An XMLData object containing the
differences between the XMLData object and the XML document specified in the
XMLDocument argument.
Filter:
0 or micXMLNone: Compares the elements and document type
declaration of the specified XML documents.
1 or micXMLAttributes: Compares the attributes of the
specified XML documents, in addition to their elements and document type
declaration. etc. for more on this see QTP Guide
This method returns a boolean value indicating whether or
not the two files are equal.
Also See:
How to find total number of child elements.
How to view ALL elements in a message box, one at a time.
How to view the VALUE of elements in a message box, one at a
time.
How to get the NAME of the root element, get the COUNT of
child
elements of root, get COUNT & NAMES of children of any
child element of root.
How to create a new XML file.
How to move/transfer text from XML file to QTP DataTable.
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
Search more on QTP here
How to move /transfer text from XML file to QTP DataTable.
XMLUtil-6: How to move /transfer text from XML file to QTP
DataTable.
XML file used:
Result of the above code run is as seen below which you can
see in the Test results window. Obviously this code can be made more intelligent.
You can always modify it according to your need.
Below is another variant of the above code, but may not be
as flexible.
Result of the above code run is as seen below which you can
see in the Test results window. Obviously this code can be made more
intelligent. You can always modify it according to your need.
Also See:
How to find total number of child elements.
How to view ALL elements in a message box, one at a time.
How to view the VALUE of elements in a message box, one at a
time.
How to get the NAME of the root element, get the COUNT of
child
elements of root, get COUNT & NAMES of children of any
child element of root.
How to create a new XML file.
How to compare two XML files.
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
Search more on QTP here
VBScript - Opening an existing word file
VBScript - Opening an existing word file
'opening an existing word document (tried with word 2007)
set word = createobject("word.application")
word.visible=true
Word.Documents.Open("C:\Documents and
Settings\sachin\My Documents\abc.docx")
Also See:
Opening a new word document
Opening a new word document and writing text to it
Opening an existing word document and appending text to it
at the end
Opening an existing word document and appending text to it
at the beginning
Saving a new word file
Saving an existing word file
Writing formatted text to a word file
Formatting all content, formatting specific paragraphs or
finding and formatting specific text in a word document
Inserting images/pictures to a word file
Creating table in a word document, adding text to cells,
adding rows to table
Printing a word file
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
VBScript - Saving a new word file
VBScript - Saving a new word file
'opening a new word document and writing text to it and
saving it
set word = createobject("word.application")
word.visible=true
set doc = word.documents.add
Set objectSelection = Word.Selection
objectSelection.TypeText "This is sample text"
doc.saveas("c:\test.docx")
Also See:
Opening a new word document
Opening an existing word document
Opening a new word document and writing text to it
Opening an existing word document and appending text to it
at the end.
Opening an existing word document and appending text to it
at the beginning.
Saving an existing word file
Writing formatted text to a word file
Formatting all content, formatting specific paragraphs or
finding and formatting specific text in a word document
Inserting images/pictures to a word file
Creating table in a word document, adding text to cells,
adding rows to table
Printing a word file
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
Search more on QTP here
VBScript - Printing a word file
VBScript - Printing a word document
Set word = CreateObject("Word.Application")
Set objectdocument =
word.Documents.Open("c:\test.docx")
objectdocument.PrintOut()
word.Quit
Also See:
Opening a new word document
Opening an existing word document
Opening a new word document and writing text to it
Opening an existing word document and appending text to it
at the end.
Opening an existing word document and appending text to it
at the beginning.
Saving a new word file
Saving an existing word file
Writing formatted text to a word file
Formatting all content, formatting specific paragraphs or
finding and formatting specific text in a word document
Inserting images/pictures to a word file
Creating table in a word document, adding text to cells,
adding rows to table
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
VBScript - Appending Data to an Excel Spreadsheet
VBScript - Appending Data to an Excel Spreadsheet
All we have to do is determine the bottom row in the used
range; the next available row for data entry will then be the row immediately
following the used range. That’s exactly how this script operates:
Const xlCellTypeLastCell = 11
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Cells(1,1) = 1
objWorksheet.Cells(2,1) = 2
objWorksheet.Cells(3,1) = 3
objWorksheet.Cells(5,1) = 4
objWorksheet.Cells(6,1) = 5
Set objRange = objWorksheet.UsedRange
objRange.SpecialCells(xlCellTypeLastCell).Activate
intNewRow = objExcel.ActiveCell.Row + 1
strNewCell = "A" & intNewRow
objExcel.Range(strNewCell).Activate
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
Search more on QTP here
VBScript - How Can I Add Additional Worksheets to an Excel
Workbook?
VBScript - How Can I Add Additional Worksheets to an Excel
Workbook?
This script adds the nine new worksheets directly after
worksheet 1 (thus pushing sheets 2 and 3 to the end of the collection):
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
Set colSheets = objWorkbook.Sheets
colSheets.Add ,objWorksheet,9
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test Professional)
Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
Search more on QTP here
VBScript - How Can I Import an Excel Spreadsheet Into an
Access Database?
VBScript - How Can I Import an Excel Spreadsheet Into an
Access Database?
Const acImport = 0
Const acSpreadsheetTypeExcel9 = 8
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase
"C:\Scripts\Test.mdb"
objAccess.DoCmd.TransferSpreadsheet acImport,
acSpreadsheetTypeExcel9, _
"Employees", "C:\Scripts\Employees.xls",
True
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait, Synchronization
New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
Search more on QTP here
VBScript - How Can I Insert a Column into a Spreadsheet?
VBScript - How Can I Insert a Column into a Spreadsheet?
Here's a script that writes a column header to columns A, B,
and C, then inserts a new, blank column between columns B and C:
Const xlShiftToRight = -4161
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Cells(1,1) = "Dataset 1"
objWorksheet.Cells(1,2) = "Dataset 2"
objWorksheet.Cells(1,3) = "Dataset 4"
Set objRange = objExcel.Range("C1").EntireColumn
objRange.Insert(xlShiftToRight)
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
VBScript - How Can I Replace Text in an Excel Spreadsheet?
VBScript - How Can I Replace Text in an Excel Spreadsheet?
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook =
objExcel.Workbooks.Open("C:\Scripts\Test.xls")
Set objWorksheet = objWorkbook.Worksheets(1)
Set objRange = objWorksheet.UsedRange
objRange.Replace "C:\Test\Image.jpg",
"C:\Backup\Image.jpg"
QTP - Home
QTP Tutorials
QTP Scripts
QTP - Quick Test
Professional
QTP Testing Process
Test Object Model
QTP Object
Repositories
Descriptive
Programming in QTP
Checkpoints in QTP -
Quick Test Professional
QTP Recordings
QTP Parameterize
Tests
QTP (Quick Test
Professional) Keyword View
Actions in QTP 9
(Quick Test Professional)
VBScript in QTP
Software Automation
Framework
QTP Sync, Wait,
Synchronization New
All About QTP
Parameters
Difference between
Image & Bitmap Checkpoint
Action input &
output Parameters
Capturing Background
Color in QTP
Object Hierarchy in
QTP
QTP Function
Libraries
QTP GetTOProperties,
GetROProperty
Search more on QTP here
VBScript - Open an Excel Spreadsheet
VBScript - Open an Excel Spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook =
objExcel.Workbooks.Open("C:\Scripts\New_users.xls")
No comments:
Post a Comment