我使用以下代码创建给定文件夹中的文件名列表。
Public Sub ListFilesInFolder(SourceFolder As Scripting.folder, IncludeSubfolders As Boolean)
Dim fName As String
Dim Lastrow As Long
On Error Resume Next
For Each FileItem In SourceFolder.Files
' display file properties
Cells(iRow, 3).Formula = FileItem.Name
Cells(iRow, 4).Formula = FileItem.Path
iRow = iRow + 1 ' next row number
Next FileItem
Range("C17").CurrentRegion.Select
Selection.Sort Key1:=Range("C17"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
With ActiveSheet
Lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
Lastrow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End With
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder, True
Next SubFolder
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
For iRow = 17 To Lastrow
Cells(iRow, 2).Formula = iRow - 16
ActiveSheet.Hyperlinks.Add Anchor:=Cells(iRow, 2), Address:="", _
TextToDisplay:=CStr(iRow - 16)
Next
End Sub
当我将鼠标悬停在超链接上时,屏幕提示'出现的是文件路径,但我想改变这一点,以便屏幕提示'是增量唯一ID。
我已经阅读了很多有关此内容的帖子,并尝试更改“
我只是想知道某人是否能够看到这个并提供一些关于我如何能够改变这一点的指导。
答案 0 :(得分:1)
如果您的目标是将鼠标悬停在文字上,那么从快速游戏中看起来似乎需要使用屏幕提示而不是 TextToDisplay 。
以下部分:
ActiveSheet.Hyperlinks.Add Anchor:=Cells(iRow, 2), Address:="", _
TextToDisplay:=CStr(iRow - 16)
尝试将其更改为:
Activesheet.Hyperlinks.Add Anchor:=Cells(iRow, 2), Address:="", _
ScreenTip:=CStr(iRow - 16)
对于测试,请创建一个空白电子表格并在A1中键入testvalue。 以下将根据需要添加悬停文本:
ActiveSheet.Hyperlinks.Add Anchor:=Cells(1, 1), Address:="", ScreenTip:=CStr(Cells(1, 1).Value)
以下内容将更改单元格中的文字,但不会影响悬停文字:
ActiveSheet.Hyperlinks.Add Anchor:=Cells(1, 1), Address:="", TextToDisplay:=Cstr("texthaschanged")
答案 1 :(得分:-1)
您可以在ScreenTip
之后的代码字符串末尾添加TextToDisplay
,如下所示:
ActiveSheet.Hyperlinks.Add Anchor:=Cells(1, 1), Address:="", TextToDisplay:=Cstr("texthaschanged"), ScreenTip:="Table Of Contents"