Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in multiple files

Status
Not open for further replies.

Newbie311

Programmer
Oct 6, 2003
30
GB
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 <> &quot;&quot; ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> &quot;.&quot; And MyName <> &quot;..&quot; 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.

hope it helps.

muzz
 
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(&quot;C:\temp\storyboards&quot;)

AddorNew = True

For Each fiL In Fld.Files

StrFil = fiL.Path
StrTit = &quot;SC: &quot; & Left(fiL.Name, 2) & &quot; &quot; & &quot;Shot ##&quot; & Mid(fiL.Name, 3, 2)

If AddorNew = True Then

'----------------------insert slide
ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutBlank).SlideIndex
'-----------------------Insert picture
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(StrFil, msoFalse, msoTrue, Left:=106, Top:=72, Width:=350, Height:=220).Select

'-----------------------Insert Text----------------------------
ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizontal, 106#, 30, 350#, 36#).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoTrue
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select

With ActiveWindow.Selection.TextRange
.Text = StrTit
With .Font
.Name = &quot;Times New Roman&quot;
.Size = 24
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With
End With
AddorNew = False
Else

'-----------------------Insert Picture

ActiveWindow.Selection.SlideRange.Shapes.AddPicture(StrFil, msoFalse, msoTrue, Left:=106, Top:=400, Width:=350, Height:=220).Select

'-----------------------Insert Text----------------------------
ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizontal, 106#, 370, 350#, 36#).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoTrue
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select

With ActiveWindow.Selection.TextRange
.Text = StrTit
With .Font
.Name = &quot;Times New Roman&quot;
.Size = 24
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With
End With
AddorNew = True
End If

Next



End Sub


Filmmaker, gentlemen and proffesional drinker



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top