processes multiple stored files : File « File Path « VBA / Excel / Access / Word

Home
VBA / Excel / Access / Word
1.Access
2.Application
3.Data Type
4.Data Type Functions
5.Date Functions
6.Excel
7.File Path
8.Forms
9.Language Basics
10.Math Functions
11.Outlook
12.PowerPoint
13.String Functions
14.Windows API
15.Word
16.XML
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VBA / Excel / Access / Word » File Path » File 
processes multiple stored files
 
Sub BatchProcess()
    Dim Files() As String
    Dim FileSpec As String
    FileSpec = "c:\text.txt"

    NewPath = ExtractPath(FileSpec)
    FoundFile = Dir(FileSpec)
    If FoundFile = "" Then
        MsgBox "Cannot find file:" & FileSpec
        Exit Sub
    End If

    FileCount = 1
    ReDim Preserve Files(FileCount)
    Files(FileCount= FoundFile

    Do While FoundFile <> ""
        FoundFile = Dir()
        If FoundFile <> "" Then
            FileCount = FileCount + 1
            ReDim Preserve Files(FileCount)
            Files(FileCount= FoundFile
        End If
    Loop

    For I = To FileCount
        Application.StatusBar = "Processing " & Files(I)
        Call ProcessFiles(Files(I))
    Next I
    Application.StatusBar = False
End Sub

Sub ProcessFiles(FileName As String)
    Workbooks.OpenText FileName:=FileName, Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(01), Array(31), Array(121))
End Sub
Function ExtractPath(Spec As StringAs String
    SpecLen = Len(Spec)
    For I = SpecLen To Step -1
        If Mid(Spec, I, 1"\" Then
            ExtractPath = Left(Spec, I - 1)
            Exit Function
        End If
    Next I
    ExtractPath = ""
End Function

 
Related examples in the same category
1.Does the specified file exist?
2.Check file existance
3.Gets the file name from the path.
4.List all files under application path
5.Select a folder
6.Select a location containing the files you want to list
7.Common File Operations Simplified
8.Use array to store a list of files
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.