How to create a hyperlink in a cell in Excel using Visual Studio?

72 Views Asked by At

I am trying to create a CV entry system where I need to save an image location in excel (i.e. create a hyperlink in one of the cell in excel) which will allow me to open the picture file directly from Excel.

Dim TextFile As String = "E:\Tests.xlsx"

If File.Exists(TextFile) Then
    File.Delete(TextFile)
End If

Dim oExcel As Object
oExcel = CreateObject("Excel.Application")
Dim eBook As Excel.Workbook
Dim eSheet As Excel.Worksheet

eBook = oExcel.Workbooks.Add
eSheet = oExcel.Worksheets(1)
' I want to create a hyperlink in a cell excel file to point at a image location in drive
eSheet.Name = "Test File"

eBook.SaveAs(TextFile)
eBook.Close()

eBook = Nothing


oExcel = Nothing
1

There are 1 best solutions below

1
Zulqarnain Jalil On

here is the code that will help you to create hyperlink in excel file

Dim range As CellRange = sheet1.Range("C3")
Dim hyperlink1 As HyperLink = sheet1.HyperLinks.Add(range)
hyperlink1.Type = HyperLinkType.File
hyperlink1.TextToDisplay = "This is a hyperlink"
hyperlink1.Address = "employee2.xlsx"