Friday, August 6, 2010

Adding Hyperlink In An Excel Sheet

Method #1

Set obj=CreateObject("Excel.Application")
obj.Visible=True

Set oWorkBooks=obj.WorkBooks.Open("C:\Desktop\Book1.xls")
Set oWorksheet=oWorkBooks.Worksheets(1)

With oWorksheet
.Hyperlinks.Add .Range("A1"),"http://qtpcodes.blogspot.com"
End With
Method #2

Set obj=CreateObject("Excel.Application")
obj.Visible=True

Set oWorkBooks=obj.WorkBooks.Open("C:\Desktop\Book1.xls")
Set oWorksheet=oWorkBooks.Worksheets(1)
sLink="http://www.qtpcodes.blogspot.com"

oWorksheet.Cells(1, 1).Value= "=HYPERLINK("&Chr(34)&sLink&Chr(34)&",""CLICK HERE"")"