SCENARIO: I want to loop through all [gs workbook]s in a folder and perform an operation on each of them.
SOLUTION:
Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String MyPath = "C:\Temp"
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile <> ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir
Loop
End Sub
NOTE: If you want to loop through .xlsx workbooks, you'll need to only change the TheFile = Dir("*.xls) to TheFile = Dir("*.xlsx).
You'll need to update even the MyPath [gs variable] to let the code to search for your [gs workbook]s.
SOURCE | LINK (Contextures.com) | LANGUAGE | ENGLISH |
Excel – VBA – Loop through all workbooks in a Folder – http://heelpbook.altervista.org/?p=1996 – HeelpBook – Visit http://www.heelpbook.net OR http://mobile.heelpbook.net on your tablet! #heelpbook @heelpbook