如果组合框文本等于列列表中的文本,则跟随右侧单元格中的超链接
If the combobox text is equal to text in a column list, then follow hyperlink in cell to the right
我在 sheet 上有一个文件描述列表,它对应于组合框中的下拉列表。我想要一个代码,这样当用户选择此下拉列表中的任何项目时,代码会识别列中的匹配文本,然后在右侧单元格中的 link 之后进行描述。
这是我目前的代码:
Private Sub Open_Button_Click()
Select Case OI_FileName
Case Is = OI_FileName.Value = Sheets("File_Paths").Range("Description").Value
With Open_Button
For Each Cell In Range("Description")
If (Selection.OI_FileName = Cell.Value) Then Exit For
ActiveCell.Offset(0, 1).Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Return
End With
End Select
End Sub
我不确定它是否正常工作,因为 VBA 显示:编译错误:没有 With 的结尾。
如能提供任何帮助,我们将不胜感激
我想这就是您要找的。 With 语句是不必要的。
Private Sub Open_Button_Click()
Dim StrFilePaths As String
Dim CurrFileName As String
CurrFileName = OI_FileName.Value
For Each Cell In Range("Description")
StrFilePaths = Cell.Value
If CurrFileName = StrFilePaths Then
Cell.Offset(0, 1).Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
End If
Next Cell
End Sub
1st,感谢 OpiesDad 的大量投入,它进行了一些调整,但我想我现在已经让它做我想做的事了。我不得不简化并将超链接放入 Range("Description") 列,但我可以接受。
现在的代码是:
Private Sub Open_Button_Click()
Dim StrFilePaths As String
Dim CurrFileName As String
CurrFileName = OI_FileName.Value
Range("Description").Activate
For Each Cell In Range("Description")
StrFilePaths = Cell.Value
If CurrFileName = StrFilePaths Then
Cell.Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
End If
Next
End Sub
再次感谢你,我真的感激不尽。
我在 sheet 上有一个文件描述列表,它对应于组合框中的下拉列表。我想要一个代码,这样当用户选择此下拉列表中的任何项目时,代码会识别列中的匹配文本,然后在右侧单元格中的 link 之后进行描述。
这是我目前的代码:
Private Sub Open_Button_Click()
Select Case OI_FileName
Case Is = OI_FileName.Value = Sheets("File_Paths").Range("Description").Value
With Open_Button
For Each Cell In Range("Description")
If (Selection.OI_FileName = Cell.Value) Then Exit For
ActiveCell.Offset(0, 1).Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Return
End With
End Select
End Sub
我不确定它是否正常工作,因为 VBA 显示:编译错误:没有 With 的结尾。
如能提供任何帮助,我们将不胜感激
我想这就是您要找的。 With 语句是不必要的。
Private Sub Open_Button_Click()
Dim StrFilePaths As String
Dim CurrFileName As String
CurrFileName = OI_FileName.Value
For Each Cell In Range("Description")
StrFilePaths = Cell.Value
If CurrFileName = StrFilePaths Then
Cell.Offset(0, 1).Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
End If
Next Cell
End Sub
1st,感谢 OpiesDad 的大量投入,它进行了一些调整,但我想我现在已经让它做我想做的事了。我不得不简化并将超链接放入 Range("Description") 列,但我可以接受。
现在的代码是:
Private Sub Open_Button_Click()
Dim StrFilePaths As String
Dim CurrFileName As String
CurrFileName = OI_FileName.Value
Range("Description").Activate
For Each Cell In Range("Description")
StrFilePaths = Cell.Value
If CurrFileName = StrFilePaths Then
Cell.Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
End If
Next
End Sub
再次感谢你,我真的感激不尽。