WORK備忘録

メモ

ハイパーリンク付け

2017-04-02 17:47:13 | 日記

Sub ハイパーリンク付け()

    Dim StartRow, StartColumn As Long
    Dim Max_Row, Max_Column As Long
    Dim LoopArea As Range

    Set LoopArea = Selection
    
    StartRow = LoopArea.Cells(1).Row '開始行
    StartColumn = LoopArea.Cells(1).Column ' ハイパーリンク列
    
    Max_Row = LoopArea.Cells(LoopArea.Count).Row '終了行
    Max_Column = LoopArea.Cells(LoopArea.Count).Column 'ファイルパス列

'Debug.Print StartRow & "開始行"
'Debug.Print StartColumn & "ハイパーリンク列"
'Debug.Print Max_Row & "終了行"
'Debug.Print Max_Column & "ファイルパス列"


'ハイパーリンク
Dim hlin As Long
    With ActiveSheet.Hyperlinks
        For hlin = StartRow To Max_Row
        'Debug.Print hlin & "hl"
            .Add Anchor:=Cells(hlin, StartColumn), Address:=Cells(hlin, Max_Column).Value
        Next hlin
    End With

End Sub