【问题标题】:Generating hyperlink from formula outcome从公式结果生成超链接
【发布时间】:2021-10-05 02:25:23
【问题描述】:

Excel 中的超链接有问题

=K1&TEXT(B5,"YYYY-MM-DD")&K2&MONTH(B5)&K3&B3&K4&TEXT(B4,"YYYY-MM-DD")&K5&MONTH(B4)&K6&1&K7&20&K8&YEAR(B4)&K9&B2&K10&YEAR(B1)

我们的想法是为我们所在的一周创建一个自动生成的报告链接。公式有效,生成的地址有效,但我无法将其转换为可点击的链接而无需复制和将其粘贴到浏览器中。

生成的链接是 351 个字符,所以我尝试仅引用包含公式的单元格,但在这两种情况下它都会抛出我 #VALUE!

当尝试使用CONCATENATE 制作公式但结果相同时

知道如何克服字符数限制吗?我想这就是问题所在。

【问题讨论】:

  • 请添加一些地址示例。
  • 地址与显示的文本不同。 VBA 中可能有一个解决方案,您可以在其中获取这些输入并将它们转换为链接,但有一个简单的显示文本可以解决此限制。
  • 这是生成的地址,它工作正常。您将无法访问它,它是一个仅限内部的网站。

标签: excel hyperlink


【解决方案1】:

试试:

=Hyperlink(K1&TEXT(B5,"YYYY-MM-DD")&K2&MONTH(B5)&K3&B3&K4&TEXT(B4,"YYYY-MM-DD")&K5&MONTH(B4)&K6&1&K7&20&K8&YEAR(B4)&K9&B2&K10&YEAR(B1),"Click for Report")

=Hyperlink(https://eu-icqa-repo.corp.amazon.com/metric/metric_daily_view/location?assist=threshold&date=2021-07-31&date_range=daily&fc=KTW1&fc_filter=EU&metric=Safety%2FAssociate+Satisfaction%09&month=07&quarter=3&report_id=161&search_type=location&start_date=2021-07-27&start_month=07&start_quarter=1&start_week=20&start_year=2021&view=op_area&week=30&year=2021,"Click for Report")

VBA 语法类似于:

Sub AddHyperlinkToCell()
Dim Link As String
Link = "https://eu-icqa-repo.corp.amazon.com/metric/metric_daily_view/location?assist=threshold&date=2021-07-31&date_range=daily&fc=KTW1&fc_filter=EU&metric=Safety%2FAssociate+Satisfaction%09&month=07&quarter=3&report_id=161&search_type=location&start_date=2021-07-27&start_month=07&start_quarter=1&start_week=20&start_year=2021&view=op_area&week=30&year=2021"

ActiveSheet.Hyperlinks.Add Range("A1"), _
Address:=Link, _
TextToDisplay:="Click Here for Report"

End Sub

【讨论】:

  • 部分有效。它克服了字符限制。但链接是动态生成的。它总是驱使我从粘贴的确切日期开始查看报告,确实非常有用,但不适用于该用例,谢谢顺便说一句!也一直在挖掘更多,发现一些似乎运作良好的东西仍然需要测试一些东西。原帖link
  • @Killroy 我很高兴你更接近你的答案,希望结合这些和你发现的东西可以得到你的结果。在我放置链接的地方,我认为您可以应用该公式,尽管我不是 100% 了解那里的语法。如果您确实弄明白了,请回来回答您自己的问题,以便对其他人有用!
  • 肯定会在第二天上班时检查所有新信息以使其充分发挥作用并回答我所得到的一切:)
【解决方案2】:

经过一番研究,如果发现一篇旧帖子为我提供了答案

Link to original post

您只需将其粘贴到工作表代码而不是模块中!并在代码中更改要生成超长超链接的单元格范围。

如果您像我一样在公式中有一些动态范围,那么您唯一需要做的就是强制刷新公式。我刚刚录制了一个快速宏,通过单击按钮将公式重新输入到单元格中。并且链接会根据所选的日期范围发生相应的变化。

希望它对其他人有用:)

下面的测试代码:

    '     davesexel     http://www.excelforum.com/excel-general/1125569-creating-in-excel-a-hyperlink-to-a-route-made-in-google-maps.html#post4311156
Private Sub Worksheet_Change(ByVal Target As Range)
'Application.EnableEvents = False 'Does not appear to need this..  I thought it would as i thought the change in the sheet done in line 60 would set this code off again. This code line would have avoided that by turning off codes of this nature ***
10      Dim strDaveLongSExelHype As String 'Done at complile time to Tell VBA initially where to go when seeing strDaveLongSexelHype anywhere else in the code ( This may likely change as required to hause changing length values      http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring.html
20      Let strDaveLongSExelHype = Target.Value 'Target is a reserved Word used for VBA for the Range Object corresponding to where you "Hit"  ( or the Range which you selected before hitting hit Enter ) The .Value Property assigned to one cell returns the value in an appropriate type, ( in our case typically a String ), of what is in the cell. In other words what you typed in is "put in" strDaveLongSExelHype
30      Dim WhereIWantToInsertMyLongThong As Range 'Variable for the Spreadsheet Area, as a Range Object, where you are expecting to Insert your Long Things.
40      Set WhereIWantToInsertMyLongThong = Range("A13:A14") ' CHANGE this to suit your wishes!  ####
'41  Set WhereIWantToInsertMyLongThong = Cells '  ##### This alternatve would result in the code working over the whole Worksheet
50      If Not Intersect(WhereIWantToInsertMyLongThong, Target) Is Nothing Then 'The VBA Intersect Method will return a Range Object that represents the intersection of two, or more, ranges. Nothing is a Special VBA Object for a "not yet assigned Object". If we Not get that then we have a Object, ( in this case a range Object ( a Cell ) ) that intercepts the entire Range where you wanted to be able to Insert your Long Thing ( That entire Range was specified in Line 40 ( or 41 ) )
'       The Hyperlink Property of a range returns ( or refers )  to a collection of  "all to do with" the Hyperlinks associated with that range Object. Amongst other things a .Add Method is available with 2 compulsory and 2 optional arguments.  Based on the arguments, a specific Hyperlink is put in the Range. Anchor:= _____ says where the Hyperlinkk is written in. Address:=_____in this case is the URL itself.  ScreenTip:=____is the bit of text in the cell which you usually put in as something like “Click Me”. But just for fun I used the whole text of your URL again.   TextToDisplay:=___Is where you put what you want to be displayed in the Box which comes up when you hover over your Hyperlink cell with the mouse. Again just for fun I used your whole URL. I guess you might want just something Like “This goes to my Google Maps Pub Crawl Route when I click on it”
60          Target.Hyperlinks.Add Anchor:=Target, Address:="" & strDaveLongSExelHype & "", ScreenTip:="" & strDaveLongSExelHype & "", TextToDisplay:="" & strDaveLongSExelHype & "" ' " DaveSexuel's Workaround " Allowing a very long  ( greater than 255 character ) URL to be put in an Excel Cell    http://www.excelforum.com/excel-general/1125569-creating-in-excel-a-hyperlink-to-a-route-made-in-google-maps.html#post4311156
'70      Else 'Do Not need to do anything here...  but just for fun, lines 70 and 75 would result in  a message box poping up telling you that you selected outside the range you specified in Line 40 ( or 41 )
'75      MsgBox prompt:="Your Selected Range was not within Area " & Replace((WhereIWantToInsertMyLongThong.Address), "$", "", 1) & ""  ' Address Property applied to Range Object returns a String including the $ bits. So a simple Replace withn that String  ,    of   a  $   ,   with  a special VBA String representing a string variable not filled yet  ,   starting looking at character  1 ( first )  ,  and replace all of them ( that is what -1 means in this case )
80          End If
Application.EnableEvents = True ' I leave this in just to be on the safe side!!  **
End Sub

【讨论】:

    猜你喜欢
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 2021-06-22
    • 2015-11-20
    • 1970-01-01
    • 2017-12-03
    相关资源
    最近更新 更多