tonywatsonhelp
Well-known Member
- Joined
- Feb 24, 2014
- Messages
- 3,178
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hi everyone,
I have this macro that goes to a folder "Patient 47" and converts all the txt to excel files, but I need it to go to all folders not just "Patient 47"
so the fiile path would be: "C:\Users\iplayer\Documents\Odesk New1\41 Odeskrune Hansen mcro\" the every folder in this folder, I don't know what those folders will be called.
is this possible? can someone please show me how to do it?
thanks
Tony
I have this macro that goes to a folder "Patient 47" and converts all the txt to excel files, but I need it to go to all folders not just "Patient 47"
so the fiile path would be: "C:\Users\iplayer\Documents\Odesk New1\41 Odeskrune Hansen mcro\" the every folder in this folder, I don't know what those folders will be called.
is this possible? can someone please show me how to do it?
thanks
Tony
Code:
Sub LoopAllFiles()
Dim sPath As String, sDir As String
sPath = "C:\Users\iplayer\Documents\Odesk New1\41 Odeskrune Hansen mcro\Patient 47"
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
sDir = Dir$(sPath & "*.txt", vbNormal)
Do Until Len(sDir) = 0
Workbooks.Open (sPath & sDir)
With ActiveWorkbook
.SaveAs Filename:=Left(.FullName, InStrRev(.FullName, ".")) & "xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
.Close
End With
sDir = Dir$
Loop
End Sub