Adding Hyperlinks in Excel Spreadsheet in QTP

Discussion in 'Programming' started by ExpertQTP, Oct 7, 2009.

  1. #1
    I was playing with the excel application along with QTP when suddenly I thought of adding a hyperlink inside an Excel spreadsheet from Quicktest. Task seemed a bit tricky initially but I took up the challenge and finally created a script.

    The QTP script to accomplish the same goes here:

    'Create an object reference to Excel. Also you can see "Excel.exe" 'process gets created in the Task Manager
    Set objExcel = CreateObject("Excel.Application")

    'Make the invisible Excel application visible
    objExcel.Visible = True

    'Add a workbook to the blank excel sheet
    Set objWorkbook = objExcel.Workbooks.Add

    'Get the handle of first sheet
    Set objWorksheet = objWorkbook.Worksheets(1)

    'Enter the value in A1 cell inside your first worksheet
    objWorksheet.Cells(1, 1) = "QTP Expert"

    'Create a range encompassing only the single cell A1
    Set objRange = objExcel.Range("A1")

    'Add a hyperlink to that range. Here range is only a single 'cell so hyperlink would be created
    Set objLink = objWorksheet.Hyperlinks.Add _
    (objRange, "http://www.quicktesthp.blogspot.com")

    You can read more QTP Articles here:
     
    ExpertQTP, Oct 7, 2009 IP