1、怎样利用 vba 将 txt 文档中的数据按照逗号分隔符依次倒入 excel文档中?Sub 文本导入()fileToOpen = Application.GetOpenFilename(“请选文本(*.txt), *.txt“, , “导入逗号分隔文本“)If fileToOpen = False ThenExit SubEnd IfRange(“A1“).SelectWith ActiveSheet.QueryTables.Add(Connection:=“TEXT;“ & fileToOpen, Destination:=Range(“A1“).FieldNames = True.RowN
2、umbers = False.FillAdjacentFormulas = False.PreserveFormatting = True.RefreshOnFileOpen = False.RefreshStyle = xlInsertDeleteCells.SavePassword = False.SaveData = True.AdjustColumnWidth = True.RefreshPeriod = 0.TextFilePromptOnRefresh = False.TextFilePlatform = 936.TextFileStartRow = 1.TextFileParse
3、Type = xlDelimited.TextFileTextQualifier = xlTextQualifierDoubleQuote.TextFileConsecutiveDelimiter = False.TextFileTabDelimiter = False.TextFileSemicolonDelimiter = False.TextFileCommaDelimiter = True.TextFileSpaceDelimiter = False.TextFileColumnDataTypes = Array(1, 1, 1).TextFileTrailingMinusNumbers = True.Refresh BackgroundQuery:=FalseEnd WithEnd Sub将导入的数据放在原来的单元格中,而不是新插入单元格:.RefreshStyle = xlInsertDeleteCells 把上面句改为下面一句即可:.RefreshStyle = xlOverwriteCells