Hi, I have a spreadsheet that runs a macro to search the current worksheet for the text entered in a text box. The code runs OK when the spreadsheet is opened from a local drive but fails unexpectedly when the spreadsheet is opened from a network drive. Any ideas what maybe causing this? Thanks
Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Dim c As Range
Dim wb As String
wb = ActiveWorkbook.Name
With Workbooks(wb).ActiveSheet.Cells
Set c = .Find(What:=TextBox1.Value, LookAt:=xlPart)
If c Is Nothing Then
r = MsgBox("Search text not found", vbExclamation, "Find")
TextBox1.Activate
Exit Sub
End If
firstAddress = c.Address
Do
If Not c Is Nothing Then
If Not (c.EntireColumn.Hidden = True Or c.EntireRow.Hidden = True) Then
Workbooks(wb).ActiveSheet.Cells(c.Row, c.Column).Select
r = MsgBox("Match found in cell " & c.Address & vbCrLf & "Continue search?", vbQuestion + vbYesNo, "Find")
If r = vbNo Then
Exit Sub
End If
End If
Set c = .Find(What:=TextBox1.Value, After:=c)
End If
Loop While Not c Is Nothing And c.Address <> firstAddress
r = MsgBox("No more matches found", vbInformation, "Find")
End With
End If
End Sub