PDA

View Full Version : Solved: open Excel filename with only certain characters



alienscript
08-20-2009, 09:30 AM
Hi Excel VBA experts,

How do I open an Excel workbook from C:\Data\ that has the first 4 characters as "item"? For example, among all the workbooks and text files in C:\Data\ folder, there is a filename called item-groups-17082009.xls and then in next week this workbook will be replaced with "item-groups-24082009.xls". There is only one file at anytime in this folder with the first 12 characters fixed as "Item-groups-".

I can't find any related threads and answers. Hope to get some help here.
Many many thanks.

Bob Phillips
08-20-2009, 09:50 AM
Dim fname As String

fname = Dir("C:\Data\item*.xls", vbNormal)
If fname <> "" Then

Workbooks.Open (fname)
'...
End If

alienscript
08-21-2009, 07:44 AM
You are truly wonderful! Thanks again.