พอดีจะทำโปรแกรมแปลงไฟล์ excel.csv มาเป็น .xls
มัน ติดอยู่ บรรทัดนี้
with Worksheets(strNameSheet).QueryTables.Add(Connection:="TEXT;"&_.Selecteditem(intcount),Destination:=WorkSheets(strNameSheet).Range("A1"))
ช่วยดูในส่วนตรงนี้หน่อยครับ
โค้ดทั้งหมด
Private Sub btnimportData_Click()
Dim strNameSheet As String
Dim ingCount As Long
Dim ingindexDot As Long
With Application.FileDialog(msoFileDialogOpen)
.Title = "Select File"
.AllowMultiSelect = True
.Show
For ingCount = 1 To .SelectedItems.Count
strNameSheet = Dir(.SelectedItems(ingCount), vbNormal)
ingindexDot = InStr(strNameSheet, "|")
strNameSheet = Left(strNameSheet, ingindexDot - 1)
Worksheets.Add Count:=1, After:=Worksheets(1)
ActiveSheet.Name = strNameSheet
with Worksheets(strNameSheet).QueryTables.Add(Connection:="TEXT;"&_.Selecteditem(intcount),Destination:=WorkSheets(strNameSheet).Range("A1"))
.Name = strNameSheet
.FieldNames = True
.RowNumber = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshStyle = xllnsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 847
.TextFileStarRow = 1
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileVarticallineDelimiter = True
.TextFileColumndataType = Array(1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=True
End With
Next ingCount
End With
End Sub
สอบถาม ?? VBA compile code ไม่ผ่าน
มัน ติดอยู่ บรรทัดนี้
with Worksheets(strNameSheet).QueryTables.Add(Connection:="TEXT;"&_.Selecteditem(intcount),Destination:=WorkSheets(strNameSheet).Range("A1"))
ช่วยดูในส่วนตรงนี้หน่อยครับ
โค้ดทั้งหมด
Private Sub btnimportData_Click()
Dim strNameSheet As String
Dim ingCount As Long
Dim ingindexDot As Long
With Application.FileDialog(msoFileDialogOpen)
.Title = "Select File"
.AllowMultiSelect = True
.Show
For ingCount = 1 To .SelectedItems.Count
strNameSheet = Dir(.SelectedItems(ingCount), vbNormal)
ingindexDot = InStr(strNameSheet, "|")
strNameSheet = Left(strNameSheet, ingindexDot - 1)
Worksheets.Add Count:=1, After:=Worksheets(1)
ActiveSheet.Name = strNameSheet
with Worksheets(strNameSheet).QueryTables.Add(Connection:="TEXT;"&_.Selecteditem(intcount),Destination:=WorkSheets(strNameSheet).Range("A1"))
.Name = strNameSheet
.FieldNames = True
.RowNumber = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshStyle = xllnsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 847
.TextFileStarRow = 1
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileVarticallineDelimiter = True
.TextFileColumndataType = Array(1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=True
End With
Next ingCount
End With
End Sub