Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath$) As Boolean
Sub Demo2a()
Const D = "C:\Users\PC\Desktop\study mst\coordinate extractions\coordinate CSVs\", E = ".csv"
Dim F$, N%, P$, S$(), U&, Z$, L&, R&
F = Dir$(D & "*" & E): If F = "" Then Beep: Exit Sub
N = FreeFile
Do
P = D & Replace(F, E, "\")
If MakeSureDirectoryPathExists(P) Then
Application.StatusBar = " Processing " & F
Open D & F For Input As #N
S = Split(Input(LOF(N), #N), vbLf)
Close #N
U = UBound(S) + (S(UBound(S)) = "")
Z = " (" & String$(Len(CStr(U)), "0") & ") "
For L = 0 To U - 1
Open P & Replace(F, E, Format(L + 1, Z) & E) For Output As #N
Print #N, "Latitude,Longitude"; vbLf; S(L);
For R = L + 1 To U - 1: Print #N, vbLf; S(R); vbLf; S(L);: Next
Print #N, vbLf; S(U);
Close #N
Next
End If
F = Dir$
Loop Until F = ""
Application.Speech.Speak "Done", True
Application.StatusBar = False
End Sub