Nguyen Anh Dung
Board Regular
- Joined
- Feb 28, 2020
- Messages
- 180
- Office Version
- 2016
- Platform
- Windows
as code below:
Sub ProcessMultipleFiles()
Dim NewFileName As String
Dim FileList As Variant, FilePath As Variant
Dim FolderPath As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FolderPath = "C:\Users\dungna\Desktop\Vidu\"
FileList = Array("GS013601.csv")
For Each FilePath In FileList
FilePath = FolderPath & FilePath
If FSO.FileExists(FilePath) Then
NewFileName = FSO.GetBaseName(FilePath)
NewFileName = NewFileName & "_Heading.csv"
FSO.CopyFile FilePath, FolderPath & NewFileName, True
CSVAmend2 FolderPath, NewFileName
Else
MsgBox FilePath & " not found"
End If
Next FilePath
End Sub
Sub CSVAmend2(FolderPath As String, FileName As String)
Dim wb As Workbook, ws As Worksheet, rng As Range, headers As Variant
headers = Array("ID", "trksegID", "lat", "lon", "ele", "time", "time_N", "Heading")
'open file (immediate save not needed)
'Set wb = Workbooks.Open("D:\test_file\test\20200310_07_002_QTB_GS023662-gps.csv")
Set wb = Workbooks.Open(FolderPath & FileName)
'wb.SaveAs ("D:\test_file\test\20200310_07_002_QTB_GS023662.csv")
Set ws = wb.Sheets(1)
Set rng = ws.Range("A2", ws.Range("A" & ws.Rows.Count).End(xlUp))
'add time columns
With rng.Offset(, 8)
.Formula = "=A2"
.Resize(, 2).NumberFormat = "YYYY-MM-DD hh:mm:ss"
.Value = .Value
.Offset(, 1).Value = .Value
End With
'add ID columns
ws.Range("C:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
rng.Formula = "=row()+1"
rng.Offset(, 1).Value = 1
'delete columns not required and insert headers
ws.Range("F:O").Delete Shift:=xlToLeft
ws.Range("A1:H1").Value = headers
'save and close
'wb.Save
wb.Close SaveChanges:=True 'False
End Sub
I have file test.csv with format as 1.jpg. i want copy file new test_heading.csv with format as 2.jpg. i have edit but only copy column lon and ele. help me!!!
column ID : Fill in the order automatically
trksegID default with value: 1
copy column Latitude->lat
copy column Longitude->lon
copy column Alevation->ele
copy column Heading->Heading
Date/Time ->Time with format "yyyy-mm-dd hh:mm:ss"
Time_N=time(7,0,0)+column time
Sub ProcessMultipleFiles()
Dim NewFileName As String
Dim FileList As Variant, FilePath As Variant
Dim FolderPath As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FolderPath = "C:\Users\dungna\Desktop\Vidu\"
FileList = Array("GS013601.csv")
For Each FilePath In FileList
FilePath = FolderPath & FilePath
If FSO.FileExists(FilePath) Then
NewFileName = FSO.GetBaseName(FilePath)
NewFileName = NewFileName & "_Heading.csv"
FSO.CopyFile FilePath, FolderPath & NewFileName, True
CSVAmend2 FolderPath, NewFileName
Else
MsgBox FilePath & " not found"
End If
Next FilePath
End Sub
Sub CSVAmend2(FolderPath As String, FileName As String)
Dim wb As Workbook, ws As Worksheet, rng As Range, headers As Variant
headers = Array("ID", "trksegID", "lat", "lon", "ele", "time", "time_N", "Heading")
'open file (immediate save not needed)
'Set wb = Workbooks.Open("D:\test_file\test\20200310_07_002_QTB_GS023662-gps.csv")
Set wb = Workbooks.Open(FolderPath & FileName)
'wb.SaveAs ("D:\test_file\test\20200310_07_002_QTB_GS023662.csv")
Set ws = wb.Sheets(1)
Set rng = ws.Range("A2", ws.Range("A" & ws.Rows.Count).End(xlUp))
'add time columns
With rng.Offset(, 8)
.Formula = "=A2"
.Resize(, 2).NumberFormat = "YYYY-MM-DD hh:mm:ss"
.Value = .Value
.Offset(, 1).Value = .Value
End With
'add ID columns
ws.Range("C:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
rng.Formula = "=row()+1"
rng.Offset(, 1).Value = 1
'delete columns not required and insert headers
ws.Range("F:O").Delete Shift:=xlToLeft
ws.Range("A1:H1").Value = headers
'save and close
'wb.Save
wb.Close SaveChanges:=True 'False
End Sub
I have file test.csv with format as 1.jpg. i want copy file new test_heading.csv with format as 2.jpg. i have edit but only copy column lon and ele. help me!!!
column ID : Fill in the order automatically
trksegID default with value: 1
copy column Latitude->lat
copy column Longitude->lon
copy column Alevation->ele
copy column Heading->Heading
Date/Time ->Time with format "yyyy-mm-dd hh:mm:ss"
Time_N=time(7,0,0)+column time