Posts

Showing posts from 2013

Treat excel as database and fetch the data based on a query

'Define variables Dim objCon , objRecordSet , strExlFile , colCount , row , i 'Set Connection object Set objCon = CreateObject ( "ADODB.Connection" ) 'Set Recordset object Set objRecordSet = CreateObject ( "ADODB.Recordset" ) 'Path of excel file strExlFile = "C:\QTP Practice\Excel as Database\TestData.xls" 'Connection string objCon.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" & strExlFile & ";Readonly=True" 'OR you can use below line for connection string 'objCon.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\test.xls;Extended Properties=Excel 12.0;Persist Security Info=False" 'Set cursor type - Very Inportant. If you fail to set it, then you will not get the correct row count objRecordset.CursorType = 1 'Query to fetch the data strSQLStatement = "SELECT * FROM [Data$]" 'Create recordset o...

VBScript to compare different file types

'Comparing Text, XML, and HTML files 'Close all open Notepad files Call CloseAllNotepadFiles () ''Close all open HTML pages 'Call CloseAllHTMLDocuments() 'Get the path of current directory FilePath = CreateObject ( "Scripting.FileSystemObject" ). GetAbsolutePathName ( "." ) 'Get files to comapare f1 = FilePath & "\files\File1.txt" f2 = FilePath & "\files\File2.txt" ''Get files to comapare 'File1 = FilePath &"\files\File1.xml" 'File2 = FilePath &"\files\File2. xml " ''Get files to comapare 'File1 = FilePath &"\files\File1.html" 'File2 = FilePath &"\files\File2.html" 'Call CompareFiles function Call Comparefiles ( f1 , f2 ) If CompareFiles ( f1 , f2 ) = False Then     MsgBox "Files are identical." Else     MsgBox "Files are different."...