snasui wrote: Sat Jul 11, 2020 5:18 pm

แนบไฟล์พร้อม Code ล่าสุดที่นำไปปรับใช้แล้วมาด้วยจะได้ดูต่อไปจากนั้นครับ
-ไฟล์และ Code ที่ผมนำไปปรับใช้ครับ
Code: Select all
Sub Input_CSV()
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Clear
.Title = "Selec a CSV File"
.Filters.Add "CSV", "*.csv", 1
Dim sFile As String
If .Show = True Then
sFile = .SelectedItems(1)
End If
End With
If sFile <> "" Then
Open sFile For Input As #1
row_number = 1
Do Until EOF(1)
Line Input #1, LineFromFile
LineItems = Split(LineFromFile, ",")
LineItem = LineFromFile
Application.Range("rRange").Cells(row_number, 1).Value = VBA.Replace(LineItems(0), """", "")
Application.Range("rRange").Cells(row_number, 2).Value = VBA.Replace(LineItems(1), """", "")
Application.Range("rRange").Cells(row_number, 3).Value = VBA.Replace(LineItems(2), """", "")
Application.Range("rRange").Cells(row_number, 4).Value = VBA.Replace(LineItems(4), """", "")
Application.Range("rRange").Cells(row_number, 5).Value = VBA.Replace(LineItems(26), """", "")
Application.Range("rRange").Cells(row_number, 6).Value = VBA.Replace(LineItems(27), """", "")
Application.Range("rRange").Cells(row_number, 7).Value = VBA.Replace(LineItems(28), """", "")
Application.Range("rRange").Cells(row_number, 8).Value = VBA.Replace(LineItems(32), """", "")
Application.Range("rRange").Cells(row_number, 9).Value = VBA.Replace(LineItems(33), """", "")
Application.Range("rRange").Cells(row_number, 10).Value = VBA.Replace(LineItems(34), """", "")
row_number = row_number + 1
Loop
Close #1
End If
End Sub