Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default DIR and Arrays

I am using the Dir function to iterate thru a directory for files with a
certain name as follows, there will be more than one file that meets the
mask

Dim myFiles
myFiles = Dir("C:\"Export_List*.xls")
Do While myFiles < ""
myFiles = Dir
Loop

My question

How do I store all the file names found into an array?



--
Cheers
Nigel




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default DIR and Arrays

On this page you can see how to do this Nigel
http://www.rondebruin.nl/copy3.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Nigel" wrote in message ...
I am using the Dir function to iterate thru a directory for files with a
certain name as follows, there will be more than one file that meets the
mask

Dim myFiles
myFiles = Dir("C:\"Export_List*.xls")
Do While myFiles < ""
myFiles = Dir
Loop

My question

How do I store all the file names found into an array?



--
Cheers
Nigel




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default DIR and Arrays

Using your code you could do it something like this...

Sub test()
Dim myFile As String
Dim myFiles() As String
Dim lng As Long

lng = 0
myFile = Dir("C:\Export_List*.xls")
Do While myFile < ""
ReDim Preserve myFiles(lng)
myFiles(lng) = myFile
myFile = Dir
lng = lng + 1
Loop

End Sub
--
HTH...

Jim Thomlinson


"Nigel" wrote:

I am using the Dir function to iterate thru a directory for files with a
certain name as follows, there will be more than one file that meets the
mask

Dim myFiles
myFiles = Dir("C:\"Export_List*.xls")
Do While myFiles < ""
myFiles = Dir
Loop

My question

How do I store all the file names found into an array?



--
Cheers
Nigel





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default DIR and Arrays

Hi Nigel,

use a collection instead of an array,
so you don't have to worry about re-dimension.

Sub Test4()
Dim oCll As Collection
Set oCll = New Collection
Dim myfiles As String

myfiles = Dir("C:\test\excel\*.xls")
Do While myfiles < ""
oCll.Add myfiles
myfiles = Dir
Loop
MsgBox oCll(1)
MsgBox oCll(oCll.Count)
End Sub

And have a look at the quotation marks in your sample.
There is one too many.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default DIR and Arrays

Thanks to all for your valued suggestions. I now have a way forward

--
Cheers
Nigel



"Helmut Weber" wrote in message
...
Hi Nigel,

use a collection instead of an array,
so you don't have to worry about re-dimension.

Sub Test4()
Dim oCll As Collection
Set oCll = New Collection
Dim myfiles As String

myfiles = Dir("C:\test\excel\*.xls")
Do While myfiles < ""
oCll.Add myfiles
myfiles = Dir
Loop
MsgBox oCll(1)
MsgBox oCll(oCll.Count)
End Sub

And have a look at the quotation marks in your sample.
There is one too many.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"





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
Working with ranges in arrays... or an introduction to arrays Glen Excel Programming 5 September 10th 06 08:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi[_2_] Excel Programming 1 August 17th 06 04:13 PM
arrays HSalim[MVP] Excel Programming 3 February 22nd 06 09:27 PM
About Arrays hke[_23_] Excel Programming 2 November 17th 04 01:29 PM
Help with arrays please Gary[_18_] Excel Programming 6 June 27th 04 08:29 PM


All times are GMT +1. The time now is 10:27 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"