Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
opening a file that will have wildcards in VBA
NHWVBA
You can't use wildcards in Workbooks.Open or Workbooks.OpenText. What if more than one file has that format? Do you want to open all of them? Just the first one? You might look into the Dir function. You can use wildcards with Dir, but only * and ?, not #. To open the first file that looks like your string Dim aname as String Dim bname as String dim mypath as String aname = range("A1").Value & "??????.dat" mypath = "c:\documents" & Format(Int(Now()), "yyyy") & "\lists" & Format(Int(Now()), "mm-yyyy") & "\" bname = Dir(mypath & aname) If Len(baname) = 0 Then 'no file found Else Workbooks.OpenText mypath & bname End If -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
opening a file in Excel starts application but dose not open file | Excel Discussion (Misc queries) | |||
Opening file in Excel 2003 opens multipule instances of same file | Excel Discussion (Misc queries) | |||
File:1 and File:2 -- Double Files when Opening One File | Excel Discussion (Misc queries) | |||
opening an excel file opens a duplicate file of the same file | Excel Discussion (Misc queries) | |||
Any way to grab a .csv file from a folder using Wildcards | Excel Programming |