macros只能在debugging模式下创build超链接

这是一个macros,它将search单个目录中包含的所有工作簿中所有工作表中的所有单元格。 除了添加超链接方法之外,所有的工作都是按照广告的方式进行的,如果我反复地对F8进行混搭,那么这个方法就行。

如何编辑macros以使超链接部分工作?

'Search all workbooks in a folder for string Sub SearchWorkbooks() Dim fso As Object Dim fld As Object Dim strSearch As String Dim strPath As String Dim strFile As String Dim wOut As Worksheet Dim wbk As Workbook Dim wks As Worksheet Dim Lrow As Long Dim rFound As Range Dim strFirstAddress As String On Error GoTo ErrHandler Application.ScreenUpdating = False strSearch = "Capacitor" strPath = "C:\!Source" Set wOut = Worksheets.Add Lrow = 1 With wOut .Name = "Results" .Cells(Lrow, 1) = "Workbook" .Cells(Lrow, 2) = "Worksheet" .Cells(Lrow, 3) = "Cell" .Cells(Lrow, 4) = "Text in Cell" .Cells(Lrow, 5) = "Link" Set fso = CreateObject("Scripting.FileSystemObject") Set fld = fso.GetFolder(strPath) strFile = Dir(strPath & "\*.xls*") Do While strFile <> "" Set wbk = Workbooks.Open _ (Filename:=strPath & "\" & strFile, _ UpdateLinks:=0, _ ReadOnly:=True, _ AddToMRU:=False) For Each wks In wbk.Worksheets Set rFound = wks.UsedRange.Find(strSearch) If Not rFound Is Nothing Then strFirstAddress = rFound.Address End If Do If rFound Is Nothing Then Exit Do Else Lrow = Lrow + 1 .Cells(Lrow, 1) = wbk.Name .Cells(Lrow, 2) = wks.Name .Cells(Lrow, 3) = rFound.Address .Cells(Lrow, 4) = rFound.Value 'This is the line that does not work 'well it actually works in debug mode but not in real time wks.Hyperlinks.Add Anchor:=Cells(Lrow, 5), Address:=wbk.FullName, SubAddress:= _ wks.Name & "!" & rFound.Address, TextToDisplay:="Link" End If Set rFound = wks.Cells.FindNext(After:=rFound) Loop While strFirstAddress <> rFound.Address Next wbk.Close (False) strFile = Dir Loop .Columns("A:D").EntireColumn.AutoFit End With 'MsgBox "Done" ExitHandler: Set wOut = Nothing Set wks = Nothing Set wbk = Nothing Set fld = Nothing Set fso = Nothing Application.ScreenUpdating = True Exit Sub ErrHandler: MsgBox Err.Description, vbExclamation Resume ExitHandler End Sub 

尝试添加工作表引用到您的Cells()调用像wks.Cells(......)