6
Tôi có mã vba dưới đây được tạo bởi trình ghi macro. Nó nhập khẩu một tập tin csv vào bảng excel hiện tại với một số cài đặt cột cụ thể. Ngay bây giờ đường dẫn đến tệp csv được mã hóa cứng thành "C: \ Users \ myuser \ Desktop \ logexportdata.csv". Làm cách nào tôi có thể thay đổi điều này để có lời nhắc thoại yêu cầu người dùng tìm tệp .csv để nhập?excel vba mở hộp thoại để nhập csv
Sub Import_log()
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\myuser\Desktop\logexportdata.csv", Destination:=Range(_
"$A$2"))
.Name = "logexportdata"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 2
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(5, 2, 2, 2, 2, 2, 9, 9, 9, 9, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
đó làm việc! Hoàn hảo, cảm ơn bạn! – jstevens13