2015-04-17 78 views
0
Dim RITMRow As Long 
Dim ws1 As Worksheet 
Dim RITMstorage As String 
Dim LastRow As Long 




Set ws1 = Sheets("Tracker") 


LastRow = ws1.Range("A" & Rows.Count).End(xlUp).Row 

For RITMRow = 2 To LastRow 


RITMstorage = ws1.Range("A" & RITMRow).Value 



ws1.Range("A" & RITMRow).Hyperlinks.Add Anchor:=ws1.Range("A" & RITMRow), _ 
    Address:="https://site.site.com/sc_req_item.do?sys_id=" & RITMstorage, _ 
    ScreenTip:="Request Number", _ 
    TextToDisplay:=RITMstorage 


Next RITMRow 


With ws1 

.Cells.Font.Size = "8" 
.Cells.RowHeight = 11.25 
.Cells.Font.Name = "Calibri" 
.Range("A1").EntireRow.RowHeight = 25 

End With 

嗨,我上面的代码在将列转换为超链接。正如你所看到的那样,每次点击按钮时效率都会很低,它会返回并将所有内容再次转换为超链接,即使那些已经是超链接的链接也是如此。请指向正确的方向。我需要一种方法来检测已经有一个超链接的偏移量为1的列,然后转换非超链接单元格。EXCEL-VBA超链接转换查询

在此先感谢。

回答

0

只是试图从细胞获得的地址和检查,看看如果你得到一个错误:

Dim url As String 
Dim isLink As Boolean 
For RITMRow = 2 To LastRow 

    On Error Resume Next 
    url = ws1.Range("A" & RITMRow).Hyperlinks(1).SubAddress 
    isLink = (Err.Number = 0) 
    On Error GoTo 0 

    If Not isLink Then 
     RITMstorage = ws1.Range("A" & RITMRow).Value 
     ws1.Range("A" & RITMRow).Hyperlinks.Add Anchor:=ws1.Range("A" & RITMRow), _ 
      Address:="https://site.site.com/sc_req_item.do?sys_id=" & RITMstorage, _ 
      ScreenTip:="Request Number", _ 
      TextToDisplay:=RITMstorage 
    End If 

Next RITMRow 
+0

哎!有用!我只想问什么超链接(1).subaddress呢?谢谢! – user2519726

+0

我尝试获取单元格中第一个超链接的SubAddress。如果没有一个,它会出错。我使用它的习惯 - Hyperlinks.Count可能也适用于大多数情况下(假设您正在使用已知的工作表)。 – Comintern

+0

@ user2519726 ...我只记得原因。见[这篇文章](http://stackoverflow.com/questions/14422003/macro-to-open-excel-hyperlink-does-not-work-when-hyperlink-generated-with-a-form)。 – Comintern