PDA

View Full Version : EXCEL 2010: Macro is not working



Ajtak
05-19-2014, 09:50 AM
Hello. I have this macro:








Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 1 Then
number = Left(Target.Value, 3)
path = ThisWorkbook.Path
With Application.FileSearch
.NewSearch
.LookIn = path
.Filename = "Invoices*" + number + "*.*"
.SearchSubFolders = False
'File = .FoundFiles(0)
If .Execute() > 0 Then
i = .FoundFiles.Count
MsgBox .FoundFiles(1)
Workbooks.Open .FoundFiles(1)
Else
MsgBox ("File not found!")
End If
End With

Cancel = True
End If
End Sub





And I need, I have this macro to work in Office 2010.

snb
05-19-2014, 10:03 AM
Filesearch isn't available anymore in Excel 2010.

Ajtak
05-19-2014, 10:15 AM
I am beginner, I see today VisualBasic almost the first time. Please edit the code. thank you

mancubus
05-19-2014, 10:42 AM
welcome to the forum.

try this:


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim fPath As String, fName As String

fPath = ThisWorkbook.Path & "\"
fName = Dir(fPath & "Invoices*" & Left(Target.Value, 3) & "*.*")

If Target.Column <> 1 Then Exit Sub

If fName <> "" Then
Workbooks.Open Filename:=fPath & fName
Else
MsgBox ("File not found!")
End If

Cancel = True

End Sub