【问题标题】:Trying to obtain the cell address that has a hyper link in试图获取具有超链接的单元格地址
【发布时间】:2022-10-13 10:03:37
【问题描述】:

我在 Excel 工作簿中使用 VBA 在特定音乐视频上打开 VLC,而没有收到有关“您确定这是安全的”的 MS 警告。 我有运行它的代码,并试图从超链接调用它。 我不想用一个按钮,视频太多,所以决定用一个超链接。 我遇到的问题是单击时的超链接不会使单元格处于活动状态。我正在使用 ActiveCell 来选择艺术家和曲目名称(列 + ActiveCell.row)。我找不到任何可以为我提供所用超链接的单元格引用的地方。 为超链接列创建了定义的名称范围。 由于超链接不会使单元格处于活动状态,因此代码将恢复为范围中的第一个。

Option Explicit

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Call Start_VLC
End Sub

Public Sub Start_VLC()
    Dim strProgName As String
    Dim strPlaceTitle As String
    Dim strLoc As String
    Dim ActCol As String
    Dim ActRow As Double

    strLoc = Range("f1").Value & Range("B" & ActiveCell.row).Value & " - " & Range("C" & ActiveCell.row).Value & ".mp4"    'F1 = MP4 location and B&C title
    strProgName = "C:\Program Files\VideoLAN\VLC\vlc.exe" 'vlc location
    strPlaceTitle = strLoc 'MP4 location
    
    MsgBox "Active Cell = " & ActiveCell.row 'just to keep track
    MsgBox "strLoc = " & strLoc
    MsgBox "strProgName = " & strProgName
    MsgBox "strPlace Title = " & strPlaceTitle

    Call Shell("""" & strProgName & """ """ & strPlaceTitle & """", vbNormalFocus)
End Sub

欢迎任何建议

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    使用 Hyperlink.Range 属性:

    返回一个 Range 对象,该对象表示指定的超链接附加到的范围。

    Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
       Start_VLC Row:=Target.Range.Row
    End Sub
    
    Public Sub Start_VLC(ByVal Row As Long)
       strLoc = Range("f1").Value & Range("B" & Row).Value & " - " & Range("C" & Row).Value & ".mp4"  
       ...
    End Sub
    

    【讨论】:

      【解决方案2】:

      请找到我使用的整体解决方案。 它包括超链接粘贴和视频通话。 它可能是冗长的,但我是一个快乐的灵魂。 干杯大本

      Option Explicit
      Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
      Call Start_VLC
      End Sub
      Public Sub Start_VLC()
          Dim strProgName As String
          Dim strPlaceTitle As String
          Dim strLoc As String
          Dim ActCol As String
          Dim ActRow As Double
          
          strLoc = Range("f1").Value & Range("B" & ActiveCell.row).Value & " - " & Range("C" & ActiveCell.row).Value & ".mp4"    'F1 = MP4 location and B&C title
          strProgName = "C:Program FilesVideoLANVLClc.exe" 'vlc location
          strPlaceTitle = strLoc 'MP4 location
          
          Call Shell("""" & strProgName & """ """ & strPlaceTitle & """", vbNormalFocus)
           
      End Sub
      
      Sub HyperlinkFill() 'Create hyperlinks to start vVLC video from click
      Dim LastRow, HyLRow As Long
          
          LastRow = Range("J1") + 5 'J1 has the total number of videos available & hyperlinks start on row 6 currently to row 3352
          
          For HyLRow = 6 To LastRow
              ActiveCell.Hyperlinks.Add Anchor:=Sheets("Searching").Range("I" & HyLRow), Address:="", SubAddress:="'Searching'!I" & HyLRow, TextToDisplay:="PLAY NOW"
          Next HyLRow
          
      
      End Sub
      

      【讨论】:

        猜你喜欢
        • 2014-07-21
        • 1970-01-01
        • 1970-01-01
        • 2014-11-22
        • 1970-01-01
        • 1970-01-01
        • 2021-06-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多