Inserting a hyperlink using vba in excelHi all,<br/><br/>I have an excel sheet that has a text column (B) and another column (H) with urls.  I would like to hyperlink the text columns with the urls.  My thought was to add a formula to the text column in which it copies the hyperlink.  Here's what I have:<br/><br/> <pre>With xlWs .Range(&quot;B2&quot;).Formula = &quot;= Hyperlink(&quot;H2&quot;)&quot; End With</pre> But my syntax for the second line:  .Range(&quot;B2&quot;).Formula = &quot;= Hyperlink(&quot;H2&quot;)&quot;    <br/><br/>ia not correct.  Could someone help me figure out how to correct this?<br/><br/>Thank you!!!<br/>© 2009 Microsoft Corporation. All rights reserved.Wed, 02 Sep 2009 07:10:26 Z4491596e-460b-4fc8-923f-428351899253http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#4491596e-460b-4fc8-923f-428351899253http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#4491596e-460b-4fc8-923f-428351899253Condor10101010101http://social.msdn.microsoft.com/Profile/en-US/?user=Condor10101010101Inserting a hyperlink using vba in excelHi all,<br/><br/>I have an excel sheet that has a text column (B) and another column (H) with urls.  I would like to hyperlink the text columns with the urls.  My thought was to add a formula to the text column in which it copies the hyperlink.  Here's what I have:<br/><br/> <pre>With xlWs .Range(&quot;B2&quot;).Formula = &quot;= Hyperlink(&quot;H2&quot;)&quot; End With</pre> But my syntax for the second line:  .Range(&quot;B2&quot;).Formula = &quot;= Hyperlink(&quot;H2&quot;)&quot;    <br/><br/>ia not correct.  Could someone help me figure out how to correct this?<br/><br/>Thank you!!!<br/>Fri, 10 Jul 2009 05:37:48 Z2009-07-10T05:37:48Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#ec0025f1-bb2a-446d-ac54-3689ade7ee0fhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#ec0025f1-bb2a-446d-ac54-3689ade7ee0fsuznalhttp://social.msdn.microsoft.com/Profile/en-US/?user=suznalInserting a hyperlink using vba in excelIt sounds as though you have more than one hyperlink you want to add, so try something like this...<br/> <br/> <br/> <pre lang=x-vbnet>Dim cL As Range Dim n As String Dim nM As String For Each cL In ActiveSheet.Range(&quot;A4:A6&quot;) nM = cL.Value If cL.Offset(0, 1).Value &lt;&gt; &quot;&quot; Then n = cL.Offset(0, 1).Value cL.Hyperlinks.Add Anchor:=cL, Address:=n, ScreenTip:=&quot;click me&quot;, TextToDisplay:=nM End If Next</pre> <br/> <br/> <br/> The range that I want to contain the hyperlinks in this example is A4:A6.<br/> The range that contains the URLs is B4:B6 (see offset(0,1))<br/> Using this example, the text in A4:A6 remains the same but is now a clickable hyperlink.<hr class="sig">&quot;The new phonebooks are here!&quot;Fri, 10 Jul 2009 13:26:01 Z2009-07-10T13:26:01Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#49462ca6-90ed-431a-9ff0-5b932804fe94http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#49462ca6-90ed-431a-9ff0-5b932804fe94Condor10101010101http://social.msdn.microsoft.com/Profile/en-US/?user=Condor10101010101Inserting a hyperlink using vba in excel<p>Hi suznal,<br/><br/>I tried your example and as I step through the code it works like a charm;  however, when the code completes and then I open the excel file, it whows that column A has links but the links do not seem to work.  Any thoughts?<br/><br/>Here's my code snippet:<br/></p> <pre lang=x-html>Dim xlApp As Excel.Application Dim xlWs As Excel.Worksheet Dim lngRowIndex As Long Dim lngListIndex As Long Dim myCount As Integer Dim RowCount As Integer Set xlApp = CreateObject(&quot;Excel.Application&quot;) xlApp.Visible = True Set xlWB = xlApp.Workbooks.Open(&quot;c:\temp\test.xls&quot;) Set xlWs = xlWB.ActiveSheet Dim cL As Range Dim n As String Dim nM As String For Each cL In ActiveSheet.Range(&quot;A2:A26&quot;) nM = cL.Value If cL.Offset(0, 1).Value &lt;&gt; &quot;&quot; Then n = cL.Offset(0, 7).Value cL.Hyperlinks.Add Anchor:=cL, Address:=n, ScreenTip:=&quot;click me&quot;, TextToDisplay:=nM End If Next xlApp.Visible = False xlWB.Save xlWB.Close Set xlWs = Nothing Set xlWB = Nothing Set xlApp = Nothing MsgBox &quot;DONE!!!!!!!!!&quot; End Sub </pre> <p>Thanks!!!!  <br/><br/>BTW,  what format do you choose when you insert vba code into the forum windows?  :)</p>Fri, 10 Jul 2009 16:42:10 Z2009-07-10T16:42:10Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#3c85a586-05a0-4084-ad58-61e0819f6422http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#3c85a586-05a0-4084-ad58-61e0819f6422suznalhttp://social.msdn.microsoft.com/Profile/en-US/?user=suznalInserting a hyperlink using vba in excelCouple of things...<br/> <br/> If you are using n as the variable for both the Address and the TextToDisplay, then you can get rid of the following in your code...<br/> <br/> <br/> <pre lang=x-vbnet>Dim nM As String</pre> <br/> and...<br/> <br/> <pre lang=x-vbnet>nM = cL.Value</pre> <br/> <br/> I think you need to correct your cell offset...<br/> You have this...<br/> <br/> <pre lang=x-vbnet> If cL.Offset(0, 1).Value &lt;&gt; &quot;&quot; Then n = cL.Offset(0, 7).Value</pre> <br/> (0,1 and then 0,7)<br/> I beleive what you want is...<br/> <br/> <pre lang=x-vbnet> If cL.Offset(0, 7).Value &lt;&gt; &quot;&quot; Then n = cL.Offset(0, 7).Value</pre> <br/> You can also right click a cell that contains a hyperlink and select 'edit hyperlink' to see what the link is.<br/> Can you right click a cell and manually add a valid link and see if it works?<br/> <br/> <br/> <br/> <br/> <br/> Finally, when I enter code I select VB.net (since there isn't an option for VBA).<br/> <br/> <br/> <br/> <br/> BTW - I use this code on several workbooks and it works perfectly, so it is tested code.<br/><hr class="sig">&quot;The new phonebooks are here!&quot;Fri, 10 Jul 2009 18:11:56 Z2009-07-10T18:11:56Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#37bf19b3-e59b-4a21-8de4-8a9f3e5222cbhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#37bf19b3-e59b-4a21-8de4-8a9f3e5222cbCondor10101010101http://social.msdn.microsoft.com/Profile/en-US/?user=Condor10101010101Inserting a hyperlink using vba in excel<p>Thank you suznal!  I discovered what my issue is.  For some reason the file is being saved as a Microsoft Excel 5.0/95 Workbook and what it should be saving it as should be a Excel 97-2003 Workbook.<br/><br/>Any ideas at how I could fix this?<br/><br/>Here's my code snippet.  Thanks!!!</p> <pre lang=x-vbnet>Private Sub Command0_Click() Dim myQuery As QueryDef Dim openTable As TableDef Dim dbCurrent As Database Set dbCurrent = DBEngine.Workspaces(0).Databases(0) DoCmd.OutputTo acOutputQuery, &quot;qry_Offerings&quot;, acFormatXLS, &quot;c:\temp\test.xls&quot;, False Dim xlApp As Excel.Application Dim xlWB As Excel.Workbook Dim xlWs As Excel.Worksheet Set xlApp = CreateObject(&quot;Excel.Application&quot;) xlApp.Visible = True Set xlWB = xlApp.Workbooks.Open(&quot;c:\temp\test.xls&quot;) Set xlWs = xlWB.ActiveSheet Dim cL As Range Dim n As String For Each cL In ActiveSheet.Range(&quot;A2:A26&quot;) If cL.Offset(0, 7).Value &lt;&gt; &quot;&quot; Then n = cL.Offset(0, 7).Value cL.Hyperlinks.Add Anchor:=cL, Address:=n, ScreenTip:=&quot;click me&quot; End If Next xlApp.Visible = False xlWB.Save xlWB.Close Set xlWs = Nothing Set xlWB = Nothing Set xlApp = Nothing MsgBox &quot;DONE!!!!!!!!!&quot; End Sub</pre>Fri, 10 Jul 2009 20:04:44 Z2009-07-10T20:04:44Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#fcf675f6-3954-4c10-8ee8-fef89e0ec109http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/4491596e-460b-4fc8-923f-428351899253#fcf675f6-3954-4c10-8ee8-fef89e0ec109Condor10101010101http://social.msdn.microsoft.com/Profile/en-US/?user=Condor10101010101Inserting a hyperlink using vba in excelI figured it out:<br/><br/> <pre lang=x-vbnet>xlApp.DisplayAlerts = False xlWB.SaveAs &quot;C:\temp\test.xls&quot;, FileFormat:=56 xlApp.DisplayAlerts = True</pre> Thanks for all your help suznal!!!Fri, 10 Jul 2009 20:14:36 Z2009-07-10T20:14:36Z