PC Review


Reply
Thread Tools Rate Thread

DIR and Arrays

 
 
Nigel
Guest
Posts: n/a
 
      1st May 2007
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




 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      1st May 2007
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" <nigel-(E-Mail Removed)> wrote in message news:%(E-Mail Removed)...
>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
>
>
>
>

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      1st May 2007
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
>
>
>
>
>

 
Reply With Quote
 
Helmut Weber
Guest
Posts: n/a
 
      1st May 2007
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 With Quote
 
Nigel
Guest
Posts: n/a
 
      2nd May 2007
Thanks to all for your valued suggestions. I now have a way forward

--
Cheers
Nigel



"Helmut Weber" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting native arrays to managed arrays Bob Altman Microsoft VC .NET 8 27th Feb 2008 11:33 PM
Trouble with arrays (transferring values between two arrays) Keith R Microsoft Excel Programming 4 14th Nov 2007 12:00 AM
Jagged Arrays Problem - How to Assign Arrays to an Array Zigs Microsoft Excel Programming 3 11th Apr 2007 01:39 AM
Working with ranges in arrays... or an introduction to arrays =?Utf-8?B?R2xlbg==?= Microsoft Excel Programming 5 10th Sep 2006 08:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi Microsoft Excel Programming 1 17th Aug 2006 04:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:13 PM.