Hi there,I need to read in multiple txt files at once,there may be a method of specifying a folder and then searching it.If anyone can provide me with the basic code please do?Thanks
Look up FileSystemObject in VBA help, and Dir. Here's an example Dir routine:
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop
Dir searches a specified folder, and FielSystemObject you can use to manipulate files, just as if you were in Windows Explorer.
try lookingup in VBA help for filesystemobject, kind of off topic but here is a bit of code i use to go through folders to add pictures to a powerpoint presentation from files in a folder using the filesystem object, but you can also use the object to search as well
dont forget to reference it
Sub CrtPresentation()
Dim FsO As FileSystemObject
Dim Fld As Folder
Dim fiL As File
Dim StrFil As String
Dim StrTit As String
Dim AddorNew As Boolean
Set FsO = New FileSystemObject
Set Fld = FsO.GetFolder("C:\temp\storyboards"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.