{"id":68593,"date":"2005-11-04T14:05:00","date_gmt":"2005-11-04T14:05:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/11\/04\/how-can-i-add-a-hyperlink-to-an-excel-spreadsheet\/"},"modified":"2005-11-04T14:05:00","modified_gmt":"2005-11-04T14:05:00","slug":"how-can-i-add-a-hyperlink-to-an-excel-spreadsheet","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-add-a-hyperlink-to-an-excel-spreadsheet\/","title":{"rendered":"How Can I Add a Hyperlink to an Excel Spreadsheet?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I add a hyperlink to an Excel spreadsheet?<BR><BR>&#8212; J B-N<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, J B-N. To begin with, we\u2019d like to point out that we\u2019re well aware of all the recent media scandals involving such prestigious organizations as <I>The New York Times<\/I>. As you know, many of those scandals revolve around writers who didn\u2019t actually do the work they claimed they did. We wanted to take a moment to set everyone\u2019s mind at ease: the Scripting Guys would never take shortcuts in an attempt to fool our readers into thinking we did work that we didn\u2019t really do.<\/P>\n<P>OK, OK, we admit it: we really didn\u2019t do any work when it came time to answer this question. <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/feb05\/hey0215.mspx\"><B>Awhile back<\/B><\/A> we answered a similar question about adding a hyperlink to a Microsoft Word document. In order to answer this question, we pretty much took the script we wrote for that column, crossed out <I>Microsoft Word<\/I> and wrote in <I>Microsoft Excel<\/I>. We are suitably ashamed and embarrassed and we promise that something like this will never happen again.<\/P>\n<P>Well, not unless someone wants to know how to add a shortcut to a PowerPoint presentation \u2026.<\/P>\n<P>Admittedly, we didn\u2019t exactly knock ourselves out for today\u2019s column; on the bright side, however, everyone gets a useful little script out of the deal. If you want to add a hyperlink to an Excel spreadsheet here\u2019s what you need to do:<\/P><PRE class=\"codeSample\">Set objExcel = CreateObject(&#8220;Excel.Application&#8221;)\nobjExcel.Visible = True<\/p>\n<p>Set objWorkbook = objExcel.Workbooks.Add\nSet objWorksheet = objWorkbook.Worksheets(1)<\/p>\n<p>objWorksheet.Cells(1, 1) = &#8220;Script Center&#8221;<\/p>\n<p>Set objRange = objExcel.Range(&#8220;A1&#8221;)\nSet objLink = objWorksheet.Hyperlinks.Add _\n    (objRange, &#8220;http:\/\/www.microsoft.com\/technet\/scriptcenter&#8221;)\n<\/PRE>\n<P>As you can see, we begin by creating an instance of the <B>Excel.Application<\/B> object and then setting the <B>Visible<\/B> property to True; that gives us a running instance of Microsoft Excel that we can see onscreen. Next we use these two lines of code to create a new workbook and a new worksheet:<\/P><PRE class=\"codeSample\">Set objWorkbook = objExcel.Workbooks.Add\nSet objWorksheet = objWorkbook.Worksheets(1)\n<\/PRE>\n<P>Once we have that worksheet we then use this line of code to add the term \u201cScript Center\u201d to cell A1 (that is, cell row <B>1<\/B>, column <B>1<\/B>):<\/P><PRE class=\"codeSample\">objWorksheet.Cells(1, 1) = &#8220;Script Center&#8221;\n<\/PRE>\n<P>As you probably figured out, we\u2019re going to use Script Center as the hyperlink text.<\/P>\n<P>OK, so what <I>about<\/I> the hyperlink? Well, to begin with, we need to create an instance of the Excel <B>Range<\/B> object, an instance that will encompass the hyperlink text. Because we want to hyperlink to appear in cell A1 we create a range that consists solely of cell A1:<\/P><PRE class=\"codeSample\">Set objRange = objExcel.Range(&#8220;A1&#8221;)\n<\/PRE>\n<P>All that\u2019s left now is to call the <B>Add<\/B> method and add a new link to the <B>Hyperlinks<\/B> collection. Here\u2019s how we do that:<\/P><PRE class=\"codeSample\">Set objLink = objWorksheet.Hyperlinks.Add _\n    (objRange, &#8220;http:\/\/www.microsoft.com\/technet\/scriptcenter&#8221;)\n<\/PRE>\n<P>Pretty simple, huh? We just call the Add method and pass it two parameters: the object reference for our Range object (objRange) and the URL for the hyperlink (http:\/\/www.microsoft.com\/technet\/scriptcenter). You\u2019ll now be able to click on cell A1 and transport yourself to the Script Center. <\/P>\n<P>Yes, <I>exactly<\/I> like the transporters on the old <I>Star Trek<\/I> TV show.<\/P>\n<P>OK, OK, we admit it: it\u2019s nothing at all like the transporters on the old <I>Star Trek<\/I> TV show. You guys are a tough audience; if this keeps up we might have to start telling the truth once in awhile. With that in mind, the Scripting Guys would like to issue the following corrections: Dean Tsaltas is from Canada, not Pluto. Peter Costantini isn\u2019t 537 years old (not till April anyway) and Jean Ross is not a talking squirrel. Finally, Greg Stemp did <I>not<\/I> win the 1937 Miss Nebraska beauty pageant; in fact, he did not even place in the top 10.<\/P>\n<P>We hope you\u2019re satisfied now.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I add a hyperlink to an Excel spreadsheet?&#8212; J B-N Hey, J B-N. To begin with, we\u2019d like to point out that we\u2019re well aware of all the recent media scandals involving such prestigious organizations as The New York Times. As you know, many of those scandals revolve around writers [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[48,49,3,5],"class_list":["post-68593","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-excel","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I add a hyperlink to an Excel spreadsheet?&#8212; J B-N Hey, J B-N. To begin with, we\u2019d like to point out that we\u2019re well aware of all the recent media scandals involving such prestigious organizations as The New York Times. As you know, many of those scandals revolve around writers [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=68593"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68593\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=68593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}