2013-04-26 44 views
0

我在表示數據流中的進程的圖中有形狀;基於形狀和形狀名稱中的文本(例如,名爲「Control ##」的形狀,其中文本「ABC」鏈接到定義ABC過程的選項卡),形狀超鏈接到位於另一個選項卡中的過程定義。如果我將形狀中的文本更改爲「XYZ」,即是否希望超鏈接轉到「XYZ」定義,是否有自動更新該形狀中的超鏈接的方法?我嘗試過SheetFollowHyperlink事件過程,但似乎沒有發生。代碼我到目前爲止如下:當超鏈接被點擊時,有沒有辦法刷新/更新形狀中的超鏈接?

Sub AssignHyperlink() 

Dim CallerShapeName As String 
CallerShapeName = Application.Caller 

With ActiveSheet 
    Dim CallerShape As Shape 
    Set CallerShape = .Shapes(CallerShapeName) 

    Dim RowVar As Integer 

    Err.Number = 0 
    On Error Resume Next 

    If InStr(CallerShapeName, "Control") = 1 Then 

     RowVar = Application.WorksheetFunction _ 
      .Match(.Range("C2").Value & CallerShape.TextFrame2.TextRange.Text, _ 
      Sheets("Control Point Log").Range("A1:A700"), 0) 

     If (Err.Number = 1004) Then 
      MsgBox "No match found for this shape text in the Control Point Log" 
      Exit Sub 
     End If 

     On Error GoTo 0 

     .Hyperlinks.Add Anchor:=CallerShape, _ 
     Address:=ActiveWorkbook.Name & "#" & "'Control Point Log'!$C$" & RowVar 

    Else 

     RowVar = Application.WorksheetFunction _ 
      .Match(.Range("C2").Value & CallerShape.TextFrame2.TextRange.Text, _ 
      Sheets("Data Flow Glossary").Range("A1:A700"), 0) 

     If (Err.Number = 1004) Then 
      MsgBox "No match found for this shape text in the Data Flow Glossary" 
      Exit Sub 
     End If 

     On Error GoTo 0 

     .Hyperlinks.Add Anchor:=CallerShape, _ 
     Address:=ActiveWorkbook.Name & "#" & "'Data Flow Glossary'!$C$" & RowVar 

    End If 

End With 

End Sub 
+0

當單擊形狀時,爲什麼不檢索形狀的文本並使用它直接導航到相關的工作表?或者我錯過了什麼? – 2013-04-26 23:18:11

+0

我正在使用形狀的文本進行鏈接,但是當我更改文本時,它不會使用新文本重新鏈接形狀。 – 2013-04-27 02:20:31

+0

你用哪種方式定義hyperling的目的地?他們只是'選項卡'(張)名稱,或者您在工作簿中使用「命名範圍」? – 2013-04-27 05:52:05

回答

1

1st。我假設你的目標是在你點擊形狀後導航到工作簿中的範圍

2nd。要導航到的範圍被命名爲範圍。

3rd。要導航的範圍等於形狀中的文本。

我的建議是使用onAction觸發形狀(assign macro時形狀的右鍵)

4RD。我們需要以下程序 - 一個適用於所有形狀。

Sub Hyperlink_Workaround() 
    On Error GoTo ErrorHandler 

    Dim curHL As String 
     curHL = ActiveSheet.Shapes(Application.Caller).TextFrame2.TextRange.Text 

    'which way do you define destination? 
    'this way you go to named range 

    Application.Goto Range(curHL), True 
    Exit Sub 
ErrorHandler: 
    MsgBox "There is no range like " & curHL 
End Sub 

5th。單擊任何形狀後,我們將在工作簿中移動到ABC或DEF範圍,然後測試,在分配上述宏的工作表上具有以下形狀。 enter image description here

6th。當您嘗試導航到不存在的範圍時,我爲情況添加了處理程序。

+0

+ 1準確地說我的觀點。 OP遲到了,否則我會在昨天貼上幾乎相同的代碼。 – 2013-04-27 07:02:27

+0

謝謝,這確實有效,但我有大量的單元格,我不得不爲此命名(超過225)。是否有任何其他解決方法可以爲超鏈接提供建議?如果我檢查超鏈接拳頭並將其替換?這會起作用嗎? – 2013-04-29 19:25:48

+0

我不確定我是否能夠正確回答您的問題......您寫過:'我想要超鏈接然後轉到「XYZ」定義?所以,這意味着你有這個定義。所以,你在哪裏和在哪裏存儲XYZ應該打開類似Sheet(「Foo」)的信息。範圍(「A100」)... – 2013-04-29 19:37:09