+ Reply to Thread
Results 1 to 6 of 6

Filename array

  1. #1
    Registered User
    Join Date
    04-21-2006
    Posts
    61

    Filename array

    Hi All,
    I need to cycle a set of command for each file in a list... the files do not share folders, or filename structure or anything, so I really need to hard-code the filenames in, and then define the next name after each iteration. What's the best way of doing this... presumably define an array of names and then cycle that?? How do I do that then?!

    Thanks, as always,

    Gareth

  2. #2
    Ardus Petus
    Guest

    Re: Filename array

    dim MyArray as Variant
    dim i as long
    MyArray=Array("one.xls","two.xls","three.xls")
    For i = Lbound(MyArray) to Ubound(MyArray)
    Msgbox MyArray(i)
    Next i

    HTH
    --
    AP

    "pianoman" <pianoman.28q1gp_1149162063.6381@excelforum-nospam.com> a écrit
    dans le message de news:
    pianoman.28q1gp_1149162063.6381@excelforum-nospam.com...
    >
    > Hi All,
    > I need to cycle a set of command for each file in a list... the files
    > do not share folders, or filename structure or anything, so I really
    > need to hard-code the filenames in, and then define the next name after
    > each iteration. What's the best way of doing this... presumably define
    > an array of names and then cycle that?? How do I do that then?!
    >
    > Thanks, as always,
    >
    > Gareth
    >
    >
    > --
    > pianoman
    > ------------------------------------------------------------------------
    > pianoman's Profile:
    > http://www.excelforum.com/member.php...o&userid=33712
    > View this thread: http://www.excelforum.com/showthread...hreadid=547409
    >




  3. #3
    Norman Jones
    Guest

    Re: Filename array

    Hi Gareth,

    Try something like:

    '=============>>
    Public Sub Tester()
    Dim arr As Variant
    Dim i As Long

    arr = Array("A.xls", "B.xls", "C.xls", _
    "D.xls", "E.xls", "F.xls")

    For i = LBound(arr) To UBound(arr)
    'Do something, e.g.:
    MsgBox arr(i)
    Next i

    End Sub
    '<<=============



    ---
    Regards,
    Norman



    "pianoman" <pianoman.28q1gp_1149162063.6381@excelforum-nospam.com> wrote in
    message news:pianoman.28q1gp_1149162063.6381@excelforum-nospam.com...
    >
    > Hi All,
    > I need to cycle a set of command for each file in a list... the files
    > do not share folders, or filename structure or anything, so I really
    > need to hard-code the filenames in, and then define the next name after
    > each iteration. What's the best way of doing this... presumably define
    > an array of names and then cycle that?? How do I do that then?!
    >
    > Thanks, as always,
    >
    > Gareth
    >
    >
    > --
    > pianoman
    > ------------------------------------------------------------------------
    > pianoman's Profile:
    > http://www.excelforum.com/member.php...o&userid=33712
    > View this thread: http://www.excelforum.com/showthread...hreadid=547409
    >




  4. #4
    Registered User
    Join Date
    04-21-2006
    Posts
    61

    Thanks

    Excellent. Thanks guys! what would I do without this forum?!

    Cheers

  5. #5
    Tom Ogilvy
    Guest

    Re: Filename array

    An added thought.
    If the list of files will change, it might be easier to list them on a
    worksheet then you can do

    Dim v as Variant
    with Worksheets("FileList")
    set rng = .Range(.Cells(1,1),.Cells(1,1).End(xldown))
    End With
    v = rng.Value
    for i = lbound(v) to ubound(v)
    msgbox v(i,1)
    Next

    note that this is a 2D array with the second dimension 1 to 1.

    --
    Regards,
    Tom Ogilvy


    "pianoman" <pianoman.28q2um_1149163802.4509@excelforum-nospam.com> wrote in
    message news:pianoman.28q2um_1149163802.4509@excelforum-nospam.com...
    >
    > Excellent. Thanks guys! what would I do without this forum?!
    >
    > Cheers
    >
    >
    > --
    > pianoman
    > ------------------------------------------------------------------------
    > pianoman's Profile:

    http://www.excelforum.com/member.php...o&userid=33712
    > View this thread: http://www.excelforum.com/showthread...hreadid=547409
    >




  6. #6
    Registered User
    Join Date
    04-21-2006
    Posts
    61
    Thanks Tom,
    Actually, I already have a list of entries from which I could derive the filenames, so that may be the easiest thing anyway.

    Thanks for the follow-up..
    Gareth

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1