Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
opening a file in Excel starts application but dose not open file Bob Shelton Excel Discussion (Misc queries) 1 July 2nd 08 07:51 PM
Opening file in Excel 2003 opens multipule instances of same file Ed_B Excel Discussion (Misc queries) 1 June 21st 07 07:10 PM
File:1 and File:2 -- Double Files when Opening One File dallin Excel Discussion (Misc queries) 1 January 25th 07 02:53 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
Any way to grab a .csv file from a folder using Wildcards David Johnston Excel Programming 3 July 22nd 03 03:52 AM


All times are GMT +1. The time now is 08:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"