+ Reply to Thread
Results 1 to 3 of 3

Using VBA to access files in a list in EXCEL

  1. #1
    Barb Reinhardt
    Guest

    Using VBA to access files in a list in EXCEL

    I have a list of file names (with directory path included) in Column A of a
    worksheet. I'd like to generate a loop in VBA to access each of those
    files and perform a sequence of activities on the list of documents. How
    would I do that? The start and end row may vary.

    Is there a resource that I could view that would help me with this?

    Thanks,
    Barb Reinhardt

  2. #2
    Bob Phillips
    Guest

    Re: Using VBA to access files in a list in EXCEL

    Barb,

    Here is an example using FSO. It opens worksheets and copies data. AMend
    that bit for your purposes.

    Sub ProcessFiles()
    Dim i As Long
    Dim sFolder As String
    Dim fldr As Object
    Dim Folder As Object
    Dim file As Object
    Dim Files As Object
    Dim this As Workbook
    Dim cnt As Long

    Set FSO = CreateObject("Scripting.FileSystemObject")

    Set this = ActiveWorkbook
    sFolder = "C:\MyTest"
    If sFolder <> "" Then
    Set Folder = FSO.GetFolder(sFolder)

    Set Files = Folder.Files
    cnt = 1
    For Each file In Files
    If file.Type = "Microsoft Excel Worksheet" Then
    Workbooks.Open Filename:=file.Path
    this.Worksheets.Add.Name = "File" & cnt
    With ActiveWorkbook
    .Worksheets(1).Range("A1:C100").Copy _
    Destination:=this.Worksheets("File" &
    cnt).Range("A1")
    .Close
    End With
    cnt = cnt + 1
    End If
    Next file

    End If ' sFolder <> ""

    End Sub

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Barb Reinhardt" <[email protected]> wrote in message
    news:[email protected]...
    > I have a list of file names (with directory path included) in Column A of

    a
    > worksheet. I'd like to generate a loop in VBA to access each of those
    > files and perform a sequence of activities on the list of documents. How
    > would I do that? The start and end row may vary.
    >
    > Is there a resource that I could view that would help me with this?
    >
    > Thanks,
    > Barb Reinhardt




  3. #3
    PY & Associates
    Guest

    Re: Using VBA to access files in a list in EXCEL

    Try something like this

    first row is 1
    last_ row=range("A65536").end(xlup).row
    for i=1 to last_ row
    workbook.open range("A" & i)
    do something
    workbook.close
    next i

    "Barb Reinhardt" <[email protected]> wrote in message
    news:[email protected]...
    > I have a list of file names (with directory path included) in Column A of

    a
    > worksheet. I'd like to generate a loop in VBA to access each of those
    > files and perform a sequence of activities on the list of documents. How
    > would I do that? The start and end row may vary.
    >
    > Is there a resource that I could view that would help me with this?
    >
    > Thanks,
    > Barb Reinhardt




+ 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