Giúp đổi code chọn folder hoặc file!!!

Liên hệ QC

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
Cả nhà giúp đổi code khi chạy chỉ cần chọn folder hoặc chọn file trong folder để chạy, không cần phải nhập list file như dưới. Cám ơn cả nhà!!!
FileList = Array("20200310_07_002_QTB_GS023662-gps.csv", "20200310_07_003_QTB_GS033662-gps.csv", "20200310_07_004_QTB_GS043662-gps.csv")

Mã:
Dim FolderPath As String

Dim FSO As Object

Set FSO = CreateObject("Scripting.FileSystemObject")

FolderPath = "D:\test_file\"

FileList = Array("20200310_07_002_QTB_GS023662-gps.csv", "20200310_07_003_QTB_GS033662-gps.csv", "20200310_07_004_QTB_GS043662-gps.csv")

For Each FilePath In FileList

FilePath = FolderPath & FilePath

If FSO.FileExists(FilePath) Then

NewFileName = FSO.GetBaseName(FilePath)

NewFileName = Left(NewFileName, Len(NewFileName) - 4) & "_N.csv"

FSO.CopyFile FilePath, FolderPath & NewFileName, True

CSVAmend2 FolderPath, NewFileName

Else

MsgBox FilePath & " not found"

End If

Next FilePath

End Sub
 
Mã:
    Dim FolderPath As String, FilePath As String, NewFileName As String
    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = True
        .Filters.Clear
        .Filters.Add "CSV (MS-DOS)", "*.csv"
        If .Show Then
            FolderPath = FSO.GetParentFolderName(.SelectedItems(1)) & "\"
            For i = 1 To .SelectedItems.Count
                FilePath = .SelectedItems(i)
                NewFileName = FSO.GetBaseName(FilePath)
                NewFileName = Left(NewFileName, Len(NewFileName) - 4) & "_N.csv"
                FSO.CopyFile FilePath, FolderPath & NewFileName, True
                CSVAmend2 FolderPath, NewFileName
            Next
        End If
    End With
 
Upvote 0
Mã:
    Dim FolderPath As String, FilePath As String, NewFileName As String
    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = True
        .Filters.Clear
        .Filters.Add "CSV (MS-DOS)", "*.csv"
        If .Show Then
            FolderPath = FSO.GetParentFolderName(.SelectedItems(1)) & "\"
            For i = 1 To .SelectedItems.Count
                FilePath = .SelectedItems(i)
                NewFileName = FSO.GetBaseName(FilePath)
                NewFileName = Left(NewFileName, Len(NewFileName) - 4) & "_N.csv"
                FSO.CopyFile FilePath, FolderPath & NewFileName, True
                CSVAmend2 FolderPath, NewFileName
            Next
        End If
    End With
Cám ơn anh huuthang_bd rất nhiều
 
Upvote 0
Web KT

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

Back
Top Bottom