Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ksh ksh is offline
external usenet poster
 
Posts: 16
Default Wildcard in workbooks open code

Is there a way to use wild cards for the "709" part of the "200709" string
since the last two digits change every month and the 7 will change at year
end. I tried the wildcards noted in excel VBA help
("...PCC*.xls","...200???.xls","...200###") on just the file name (I haven't
even tried the folder name yet) and none of them worked.

Workbooks.Open _
("Q:\LATIN AMERICA\SABRE\2007\DATA 200709\BCDLA ACTIVE PCC 200709.XLS")


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Wildcard in workbooks open code

first = true
do
if first = true then
filename = dir("c:\temp\*709.xls")
first = false
else
filename = dir()
if filename < "" then


' enter your code - filename contains the name of the file found
' filename doesn't include path, so you may have to add path
end if
loop while filename < ""

"ksh" wrote:

Is there a way to use wild cards for the "709" part of the "200709" string
since the last two digits change every month and the 7 will change at year
end. I tried the wildcards noted in excel VBA help
("...PCC*.xls","...200???.xls","...200###") on just the file name (I haven't
even tried the folder name yet) and none of them worked.

Workbooks.Open _
("Q:\LATIN AMERICA\SABRE\2007\DATA 200709\BCDLA ACTIVE PCC 200709.XLS")


  #3   Report Post  
Posted to microsoft.public.excel.programming
TC TC is offline
external usenet poster
 
Posts: 32
Default Wildcard in workbooks open code

A good answer Joel. I found it useful. I amended it very slightly, as I
needed to open all files from two folders/paths. So, same code, just set the
path (my_path) before the loop, and then concatinate the path and file name.
At the end of the loop, change my_path to the next path name, eg c:\temp2,
and then run the loop again. Can do this as many times as you need. For my
purposes I simpley use a wildcard for the file names, as i wanted o open all
the files in the folder, though of course in your original example you used
part of the file name to limit which files are opened. The principle remains
the same though.

first = true
my_path = "c:\temp1"
do
if first = true then
filename = dir("c:\temp\*.xls")
my_file = my_path & filename
first = false
else
filename = dir()
if filename < "" then

' enter your code - filename contains the name of the file found
' filename doesn't include path, so you may have to add path
end if
loop while filename < ""

Tony





"Joel" wrote:

first = true
do
if first = true then
filename = dir("c:\temp\*709.xls")
first = false
else
filename = dir()
if filename < "" then


' enter your code - filename contains the name of the file found
' filename doesn't include path, so you may have to add path
end if
loop while filename < ""

"ksh" wrote:

Is there a way to use wild cards for the "709" part of the "200709" string
since the last two digits change every month and the 7 will change at year
end. I tried the wildcards noted in excel VBA help
("...PCC*.xls","...200???.xls","...200###") on just the file name (I haven't
even tried the folder name yet) and none of them worked.

Workbooks.Open _
("Q:\LATIN AMERICA\SABRE\2007\DATA 200709\BCDLA ACTIVE PCC 200709.XLS")


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Wildcard in workbooks open code

Maybe this is what you want to do this

dim strMonth, strYear, strDate as string

strMonth=format$(Month(Now), "00")
strYear=format$(Year(Now), "####")
strDate=strYear+strMonth

Workbooks.Open _
("Q:\LATIN AMERICA\SABRE\2007\DATA 200709\BCDLA ACTIVE PCC
+"strDate+".XLS")


Faisal...

On Nov 2, 3:44 pm, ksh wrote:
Is there a way to use wild cards for the "709" part of the "200709" string
since the last two digits change every month and the 7 will change at year
end. I tried the wildcards noted in excel VBA help
("...PCC*.xls","...200???.xls","...200###") on just the file name (I haven't
even tried the folder name yet) and none of them worked.

Workbooks.Open _
("Q:\LATIN AMERICA\SABRE\2007\DATA 200709\BCDLA ACTIVE PCC 200709.XLS")



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
vba code to open workbooks Rebecca1 Excel Worksheet Functions 3 March 5th 08 05:15 PM
macro or code to open multiple workbooks Duane Reynolds Excel Discussion (Misc queries) 1 March 14th 06 08:18 AM
Using Wildcard on Workbooks.Open Stever Excel Programming 1 October 12th 05 09:55 PM
Using a Variable in the Workbooks.Open code Phatchef24[_8_] Excel Programming 1 November 3rd 04 10:40 PM
Using a Variable in the Workbooks.Open code Phatchef24[_7_] Excel Programming 1 November 3rd 04 09:40 PM


All times are GMT +1. The time now is 10:51 AM.

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

About Us

"It's about Microsoft Excel"