作者:乔山办公网日期:
返回目录:excel表格制作
怎么帮忙?1722187970
Sub 文本e68a847a686964616f362导入()
fileToOpen = Application.GetOpenFilename("请选文本(*.txt), *.txt", , "导入逗号分隔文本")
If fileToOpen = False Then
Exit Sub
End If
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fileToOpen, Destination:=Range("A1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 936
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
i=0改为i=1
if i<>0 then改为
if i=1 then
cells(i,1)=data
else
直接百打开,粘贴数度据即可知,代码道如下:
Sub xx()
Dim wb As Workbook
Set wb = Workbooks.Open(Filename:=ThisWorkbook.Path & "\1.txt", Format:=6, delimiter:=" ") '打开1.txt
Sheet1.[a1:b4] = WorksheetFunction.Transpose(wb.Sheets(1).[a1:d2].Value) '粘贴版数据权
wb.Close False '关闭1.txt
End Sub