ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   For each workbook in Folder (https://www.excelbanter.com/excel-programming/351532-each-workbook-folder.html)

Ctech[_88_]

For each workbook in Folder
 

How can I open all excel workbooks in a folder which starts with
"BFR"...

Something like this:


For each wb in folder("X")
if filename = "BFR*" then
end if
Loop


how do I write this correct?


Thanks for the help


--
Ctech


------------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...o&userid=27745
View this thread: http://www.excelforum.com/showthread...hreadid=505288


Bob Phillips[_6_]

For each workbook in Folder
 
Maybe

Sub ProcessFiles()
Dim FSO As Object
Dim i As Long
Dim sFolder As String
Dim fldr As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object


Set FSO = CreateObject("Scripting.FileSystemObject")


sFolder = "C:\myTest\myTest"
'sFolder = "c:\my documents\excel\test"
If sFolder < "" Then
Set Folder = FSO.GetFolder(sFolder)


Set Files = Folder.Files
For Each file In Files
If Left(file.Name,3) = "BFR" Then
Workbooks.Open Filename:=file.Path
With ActiveWorkbook
.SaveAs Left(.FullName, Len(.FullName) - 4), _
FileFormat:=xlTextMac
.Close savechanges:=False
End With
End If
Next file


End If ' sFolder < ""


End Sub


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Ctech" wrote in
message ...

How can I open all excel workbooks in a folder which starts with
"BFR"...

Something like this:


For each wb in folder("X")
if filename = "BFR*" then
end if
Loop


how do I write this correct?


Thanks for the help


--
Ctech


------------------------------------------------------------------------
Ctech's Profile:

http://www.excelforum.com/member.php...o&userid=27745
View this thread: http://www.excelforum.com/showthread...hreadid=505288





All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com