FAQ
How to add excel as a database in QTP??
Set con = createobject("adodb.connection")
Set rec = createobject("adodb.recordset")
con.Provider = "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=Excel 8.0"
con.Open "D:\Book1.xls"
rec.Open "select * from [Sheet1$]",con,1
While rec.EOF <> True
msgbox rec.Fields("a")
rec.MoveNext
Wend
How to Insert values from excel to Datatable in QTP???
Option Explicit
Dim objExcel
Dim objSheet
Dim intRow,intColumn,i,j
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open "C:\Documents and Settings\skumar16\Desktop\sanjeet.xls"
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objExcel.ActiveSheet.UsedRange.select
intRow = objExcel.Selection.Rows.Count
intColumn = objExcel.Selection.Columns.Count
For j=1 to intColumn
DataTable.GlobalSheet.AddParameter objSheet.cells(1,j).Value, " "
Next
For i = 2 to intRow
For j= 1 to intColumn
DataTable.GlobalSheet.SetCurrentRow(i-1)
DataTable.Value(trim(objSheet.cells(1,j).value),dtGlobalSheet) = objSheet.cells(i,j).value
Next
Next
How to Insert Images in excel one by one with QTP???
Set oChild = description.Create
Set objChilds = Browser("Registration Form Sample").Page("Registration Form Sample").ChildObjects()
'msgbox objChilds.count
Set Obj = CreateObject ("Excel.Application") 'Pass
Set objWorkbook1 = Obj.Workbooks.Open("C:\Book18.xls")
row = 3
col = 3
For i=0 to objChilds.count-1
If objChilds(i).getroproperty("micclass") <> "WebElement" and objChilds(i).getroproperty("micclass") <> "WebTable" Then
'fInsertPicture
objChilds(i).CaptureBitmap "c:\list.bmp",True
obj.ActiveSheet.cells(row,col).value =objChilds(i).getroproperty("Name")
set cell_height = obj.ActiveSheet.cells(row,col)
set myPict = obj.ActiveSheet.Pictures.Insert("c:\list.bmp")
myPict.left = cell_height.left
myPict.top = cell_height.top + 15
intx = cell_height.top + 15 + myPict.Height
row = intx/15
row = row+ 1
'myPict.Top = objWorkbook1.ActiveSheet.
'myPict.Left = 100
'myPict.Top = 100
'msgbox myPict.Height
intHeight = myPict.Height
End If
Next
objWorkbook1.Save
Obj.Workbooks.close
Obj.Quit
Getting excel values from excel if data are Spread anywhere in QTP???
Option Explicit
Dim objExcel,objSheet,oDic,strSQL,ProcColl,oWMIService
Dim intRow,intColumn
Dim i,j,k
Dim strVal
GetExcelValue("Gouri")
Public Function GetExcelValue(byRef strVal)
Set oDic = CreateObject("Scripting.dictionary")
Set objExcel = CreateObject("Excel.Application")
ObjExcel.workbooks.open("D:\example.xls")
Set objSheet = objExcel.ActiveWorkbook.Worksheets("Data")
objExcel.Sheets("Data").usedrange.select
intRow = objExcel.Selection.rows.count
intColumn = objExcel.Selection.columns.count
For i = 1 to intRow
If objSheet.cells(i,1).value = strVal Then
msgbox i
For j = 2 to intColumn
If trim(objSheet.cells(i,j).value) <> "" Then
oDic.Add objSheet.cells(i,j).value,objSheet.cells(i+1,j).value
msgbox oDic.Item(objSheet.cells(i,j).value)
End If
Next
End If
Next
Fun_KillExcel()
End Function
Kill All excel instances through QTP???
Public Function Fun_KillExcel
strSQL = "Select * From Win32_Process Where Name = 'Excel.exe'"
Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set ProcColl = oWMIService.ExecQuery(strSQL)
For Each oElem in ProcColl
oElem.Terminate
Next
Set oWMIService = Nothing
End Function
Unlock a Locked script from QC
Set QCConnection=QCUtil.QCConnection
Set con=QCConnection.command
con.CommandText="DELETE FROM LOCKS WHERE LK_USER = 'SanjeetK' "
Set recset=con.execute
How to launch QTP from Excel button???
Open one excel sheet.
Enable Developer tab -File->Excel Options ->Popular ->Check CheckBox Show developer tab in Ribbon.
Click on Developer Tab
Insert an ActiveX Button on excel sheet.
double click on that it will open the programming window
write below code
set qtApp = CreateObject("quicktest.application")
qtApp.Launch
qtApp.visible = True
qtApp.windowState = "maximized"
Find a file inside a folder and edit it with help of QTP???
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("D:\Documents")
Set oFilesCol = oFolder.Files
For Each oFile in oFilesCol
if oFile.name = "Sanjeet.txt" then
set x = OFSO.opentextFile("d:\documents\Sanjeet.txt",8,true)
x.writeline "Gouri Jena"
end IF
Next
how to open a file .What is the perpose of true and false mode there ???
set files = createobject(“scripting.filesystemobject”)
set obj1=files.opentextfile(“d:\file2.txt”,2,true) ‘ true uses for ceating txt file
set obj2=files.opentextfile(“d:\file2.txt”,1,false) ‘ false will not create any file
obj1.writeline(“write this line into file”)
str=obj2.readline
msgbox str
set files=nothing
How to add Function Library file and Object repository in run time???
Function Library
ExecuteFile "c:\functions.vbs"
Object Repository
set qtApp = CreateObject("quicktest.application")
set qtRepos = qtApp.Test.Actions("Action1").ObjectRepositories
qtRepos.add "c:\share.tsr",1
set qtApp = Nothing
set qtRepos = Nothing