| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Excel VBA シート名を指定してハイパーリンクを作成

提供: MyMemoWiki
ナビゲーションに移動 検索に移動

Excel VBA シート名を指定してハイパーリンクを作成

Excel | Excel VBA |

シート名を指定してハイパーリンクを作成する

  1. Sub CreateHyperLink()
  2. Dim sht_name As String
  3. Dim lnk_name As String
  4. Dim i As Integer
  5. Dim hit As Boolean
  6. sht_name = InputBox("シート名を入力")
  7. If Trim(sht_name) = "" Then
  8. Exit Sub
  9. End If
  10. sht_name = RTrim$(sht_name)
  11. hit = False
  12. For i = 1 To ActiveWorkbook.Sheets.Count
  13. If ActiveWorkbook.Sheets(i).Name = sht_name Then
  14. hit = True
  15. End If
  16. Next
  17. If Not hit Then
  18. Call MsgBox("一致するシートが存在しません", vbExclamation)
  19. Exit Sub
  20. End If
  21. lnk_name = "'" & sht_name & "'!A1"
  22. ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:=lnk_name
  23. With Selection.Font
  24. .Name = "MS Pゴシック"
  25. .Size = 10
  26. .Strikethrough = False
  27. .Superscript = False
  28. .Subscript = False
  29. .OutlineFont = False
  30. .Shadow = False
  31. .Underline = xlUnderlineStyleSingle
  32. .ColorIndex = 5
  33. End With
  34. End Sub