Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I would like to insert hyperlink to file into excel cell.

What I have tried:

I was trying use this code but once hyperlink is inserted to excel when I checking the hyperlink is in cell but not active until I edit the cell then press enter.
I think its happens because the hyperlink is inserted as a text.
Could anyone can help me ?

VB
<pre>Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=EXCEL_DATA\2SV REARS RFT.xls;Extended Properties = ""Excel 12.0 Xml;HDR=YES"""
        'Create an INSERT INTO SQL statement
        Dim insertStatement As String = "INSERT INTO [" & NOWEEK.Text & "$] ([LINE], [Date], [Shift], [Frame Type], [Quantity], [Problem], [Weld Number], [Welder]) VALUES ('=HYPERLINK(C:\SMART" & FRAMETYPE.Text & ".xlsx)','" + datee.Text + "','" + CHOSESHIFT.Text + "','" + FRAMETYPE.Text + "'," + QUANTITY.Text + ",'" + PROBLEM.Text + "','" + WELDNUMBER.Text + "','" + WELDERNAME.Text + "')"
        'Create a connection object to connect to the Excel Workbook
        Dim connection As New OleDbConnection(connectionString)
        'Create a command object that will execute the insert statement
        Dim command As New OleDbCommand(insertStatement, connection)
        'Open the connection, execute the statement and close the connection
        connection.Open()
        command.ExecuteNonQuery()
        connection.Close()
        'Dispose of the connection and command objects
        connection.Dispose()
        command.Dispose()
        'Call the RefreshData routine so that you can see that data was indeed added.
Posted
Updated 4-Feb-18 5:13am

In a short: to be able to add hyperlink, you have to use: Hyperlinks.Add Method (Excel)[^].
 
Share this answer
 
v2
I check that but this is to create macro in excel.
What I looking is to add hyperlink to excel cell using application created in vb .net.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900