PDA

View Full Version : Solved: Open File which contains name



Nicolaf
12-19-2012, 07:59 AM
Hi,

I have some code that opens a specific file in a directory.
I would now like to amend it so that it opens the file which contains in its name a specific word.
The word will be contained in cell F2.
For example if file name is clientnames.xls then by putting word "names" in cell F2 this file should open.
My code is below:



IName = ThisWorkbook.Sheets("Sheet1").Range("F2").Value

Set NewWkbk = Workbooks.Open(Filename:="C:\" & IName)



How do I amend code for this new function??

Thanks,

:dunno :dunno

patel
12-19-2012, 09:28 AM
Sub jolly() '
Dim wbOpen As Workbook
strPath = "D:\test\"
Dim strExtension As String
strExtension = Dir(strPath & "*" & IName & "*.xls*")
If strExtension <> "" Then
Set wbOpen = Workbooks.Open(strPath & strExtension)
End If
End Sub

Nicolaf
12-19-2012, 09:44 AM
Great works really well!

Thanks,

:hi: :hi: :rotlaugh: