简体   繁体   English

如何从 a.txt 文件中获取文本并将其写入同一个 excel 文件的新工作表中

[英]How do I get the text from a .txt file and write it in a new sheet in the same excel file

I want a whole text file to enter into a new sheet in excel.我希望将整个文本文件输入到 excel 中的新工作表中。 Right now I am only getting all values in to one cell, I want it to look like in the text file.现在我只将所有值放入一个单元格中,我希望它看起来像在文本文件中。 Like every row get one row in excel.就像每一行在 excel 中得到一行。

I have tried this tutorial but this doesn't get it.我已经尝试过本教程,但没有得到它。

https://www.excel-easy.com/vba/examples/read-data-from-text-file.html https://www.excel-easy.com/vba/examples/read-data-from-text-file.html

I solved it for you who wants to know how check below我为想知道如何查看以下内容的您解决了

Sub GetText()
Dim SheetName As String
Dim TMPWorkBook As Workbook
Dim FilePath As String
Dim TxtFilePath As String
Dim TxtFileName As String

Set WB = ThisWorkbook

SheetName = "Test_Result"
TxtFileName = "C:\getitdone.txt"

Workbooks.OpenText Filename:= _
    TxtFileName _
    , Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
    xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, _
    Comma:=False, Space:=False, Other:=True, OtherChar:="|", FieldInfo:=Array(Array(1, 1), _
    Array(2, 1)), DecimalSeparator:=".", ThousandsSeparator:=",", _
    TrailingMinusNumbers:=True

Set TMPWorkBook = ActiveWorkbook
Cells.Select
Selection.Copy
Workbooks("Getitdone.xlsm").Activate
Sheets.Add.Name = "Data"
Range("A1").PasteSpecial xlPasteValues


End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我从Excel工作表中写入内容时,如何避免在文本文件中使用换行符? - How can I avoid Line feeder in text file when I write the content from excel sheet? 如何使用 Python 将 Excel 工作表写入制表符分隔的 .txt 文件 - How to write an Excel sheet to a tab separated .txt file with Python 如何编写一个Visual Basic应用程序(Excel)程序,它将两个单元格中的文本写入一个新的文本文件? - How do I write a Visual Basic Application (Excel) program that writes text from two cells into a new text file? 使用apache POI读取Excel文件后,如何在txt文件中打印工作表? - Once I read a excel file with apache POI how do I print the sheet in a txt file? 如何从 txt 文件中获取数据并将其发送到 Excel 电子表格?(我只想要 txt 文件中“:”之后的所有内容)? - How do i get data from a txt file and send it to excel spreadsheet?(I only want everything after the “:” in the txt file)? 如何将此Excel工作表另存为asp.net中的文本文件(.txt)? - How to save this Excel sheet as Text File (.txt) in asp.net? 如何使用PowerShell将txt文件中每行的第一个单词放入Excel工作表中? - How do I take the first word from each line in txt file and put them into an Excel sheet using PowerShell? 如何将文本文件中的数据导入 Excel 工作表,其中空白行作为分隔符? - How do I import data from text file into an Excel sheet with blank rows acting as separators? 如何将 Excel 数据表作为分隔符冒号导出到 a.txt 文件? - How do I export an Excel data sheet to a .txt file as Delimiter colon? 使用C#将数据从Excel工作表写入文本文件 - Write the data from an Excel sheet to the text file using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM