Nhờ giúp code xử lý nhiều file trong thư mục bằng VBA!!! (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

nguyenanhdung8111982

Thành viên hoạt động
Tham gia
1/11/19
Bài viết
120
Được thích
33
Giới tính
Nam
Tôi có đoạn code như dưới chỉ xử lý được 1 file.
Trong trường hợp tôi muốn xử lý nhiều file trong thư mục thì sẽ chỉnh sửa sao ạ.
link file: https://docs.google.com/uc?export=download&id=1fbtVQirTQiKyTWk0Ac6gU-KpQjJtLAQ0
file gốc:20200310_07_002_QTB_GS023662-gps.csv
file muốn hoàn thành như mẫu file này: 20200310_07_002_QTB_GS023662.csv


Sub CSVAmend()
Dim wb As Workbook, ws As Worksheet, rng As Range, headers As Variant
headers = Array("ID", "trksegID", "lat", "lon", "ele", "time", "time_N")
'open file and immediately save under new name
Set wb = Workbooks.Open("D:\test_file\test\20200310_07_002_QTB_GS023662-gps.csv")
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(, 7)
.Formula = "=((G2/1000000)+25200)/86400+25569"
.Resize(, 2).NumberFormat = "YYYY-MM-DD hh:mm:ss"
.Value = .Value
.Offset(, 1).Value = .Value
End With
'add ID columns
ws.Range("B:B").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
rng.Formula = "=row()-1"
rng.Offset(, 1).Value = 1
'delete columns not required and insert headers


ws.Range("F:H").Delete Shift:=xlToLeft
ws.Range("A1:G1").Value = headers
'save and close
wb.Save
wb.Close False
End Sub
 
Lần chỉnh sửa cuối:
Web KT

Bài viết mới nhất

Back
Top Bottom