Skip i'r prif gynnwys

Sut i allforio data Excel (dewis neu daflenni) i ffeiliau Testun yn Excel?

Os yw'n ofynnol i chi gyflwyno llyfr gwaith ar ffurf ffeil testun, mae angen i chi drosi'r llyfr gwaith yn ffeiliau testun. A bydd yr erthygl hon yn cyflwyno dau ddull i chi allforio data Excel i ffeiliau testun yn hawdd.

Allforio un ddalen sengl i'r ffeil destun yn Excel

Yn ddiofyn, bydd y data Excel yn cael ei gadw fel llyfrau gwaith ar ffurf .xlsx. Fodd bynnag, gallwn allforio taflen waith o lyfr gwaith sy'n bodoli eisoes fel ffeiliau testun gyda'r Save As nodwedd. Gwnewch fel a ganlyn:

1. Symudwch i'r daflen waith y byddwch chi'n ei hallforio i ffeil testun, a chlicio Ffeil (neu Botwm swyddfa)> Save As.

2. Yn yr agoriad Save As blwch deialog, dewiswch y ffolder cyrchfan y byddwch yn cadw'r ffeil testun a allforiwyd iddo, enwwch y ffeil yn y enw ffeil blwch, ac yna dewiswch y Testun Unicode (* .txt) o'r Cadw fel math rhestr ostwng. Gweler y screenshot:
allforio i ffeil testun gyda nodwedd Save As

3. Yna bydd yn popio dau flwch deialog rhybuddio yn gofyn ichi allforio taflen waith weithredol yn unig fel ffeil testun a gadael unrhyw nodweddion anghydnaws â ffeil testun allan. Cliciwch OK botwm a Ydy botwm yn olynol.

Yna mae'r data yn y daflen waith weithredol yn cael eu hallforio fel ffeil testun newydd.

Nodyn: mae'r Save As dim ond fel ffeil testun y gall gorchymyn allforio data taflen waith weithredol. Os ydych chi am allforio holl ddata'r llyfr gwaith cyfan, mae angen i chi arbed pob taflen waith fel ffeil testun yn unigol.


Allforio dewis (neu un golofn) i ffeil testun gyda VBA

Gall y cod VBA canlynol hefyd eich helpu i allforio'r data amrediad a ddewiswyd (er enghraifft un golofn) i'r ffeil destun, gwnewch fel hyn:

1. Dal i lawr y ALT + F11 allweddi, ac mae'n agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Cliciwch Mewnosod > Modiwlau, a gludwch y cod canlynol yn y Ffenestr Modiwl.

VBA: dewis allforio neu daflen waith gyfan i'r ffeil destun

Sub ExportRangetoFile()
'Update 20130913
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

3. Yna, pwyswch F5 allwedd i redeg y cod hwn. Ac yna dewiswch yr ystod ddata rydych chi am ei allforio yn y blwch deialog popio i fyny, a chliciwch ar y OK botwm, gweler y screenshot:
Dewiswch un golofn i'w hallforio fel ffeil testun

4. Ac yn awr mewn blwch deialog Save As arall, nodwch enw ar gyfer y ffeil testun hon a ffolder i roi'r ffeil hon ynddo, a chliciwch ar y Save botwm.


Dewis allforio (neu un golofn) i ffeil testun gyda Kutools ar gyfer Excel

Mae adroddiadau Save As gall gorchymyn allforio'r holl ddata yn y daflen waith weithredol fel testun. Beth os allforio holl ddata o daflenni gwaith anweithredol penodedig, neu ran o'r data mewn taflen waith fel ffeil testun? Kutools ar gyfer Excel's Ystod Allforio i'w Ffeilio gall cyfleustodau ein helpu i allforio ac arbed y data wrth eu dewis fel ffeil testun yn hawdd.  

Kutools ar gyfer Excel - Yn llawn dros 300 o offer hanfodol ar gyfer Excel. Mwynhewch dreial 30 diwrnod llawn sylw AM DDIM heb fod angen cerdyn credyd! Lawrlwytho nawr!

1. Dewiswch y ffon y byddwch chi'n ei allforio i ffeil testun (yn ein hachos ni, rydyn ni'n dewis Colofn A), a chlicio Kutools Byd Gwaith > Mewnforio / Allforio > Ystod Allforio i'w Ffeilio, gweler y screenshot:
Excel addin: allforio dewis i ffeil testun

2. Yn y Ystod Allforio i'w Ffeilio blwch deialog, gwnewch fel y dangosir isod y llun:
Excel addin: allforio dewis i'r ffeil testun
(1) Gwiriwch y Testun Unicode opsiwn yn y fformat y ffeil adran;
(2) Gwiriwch yr opsiwn Cadw'r gwerthoedd gwirioneddol neu Cadw gwerthoedd fel y dangosir ar yr opsiwn ar y sgrin yn ôl yr angen yn yr adran opsiynau Testun;
(3) Nodwch y ffolder cyrchfan y byddwch yn cadw'r ffeil testun a allforir iddo;
(4) Cliciwch y Ok botwm.

3. Enwch y ffeil testun a allforiwyd yn y blwch deialog agoriadol newydd, a chliciwch ar y Ok botwm.
enwwch y ffeil testun a allforiwyd

Ac yna mae'r dewisiad (Colofn A dethol) wedi'i allforio fel ffeil testun a'i gadw i'r ffolder penodedig.

Kutools ar gyfer Excel - Supercharge Excel gyda dros 300 o offer hanfodol. Mwynhewch dreial 30 diwrnod llawn sylw AM DDIM heb fod angen cerdyn credyd! Get It Now


Allforio dalennau lluosog i wahanu ffeiliau testun yn Excel

Weithiau efallai y bydd angen i chi allforio taflenni gwaith lluosog i ffeiliau testun lluosog yn Excel. Efallai bod y nodwedd Save As ychydig yn ddiflas! Peidiwch â phoeni! Kutools ar gyfer Excel's Llyfr Gwaith Hollti cyfleustodau yn darparu ffordd hawdd i ddefnyddwyr Excel allforio taflenni gwaith lluosog i lawer o ffeiliau testun ar wahân gyda sawl clic. 

Kutools ar gyfer Excel - Yn llawn dros 300 o offer hanfodol ar gyfer Excel. Mwynhewch dreial 30 diwrnod llawn sylw AM DDIM heb fod angen cerdyn credyd! Lawrlwytho nawr!

1. Cliciwch Kutools Byd Gwaith > Llyfr GwaithLlyfr Gwaith Hollti. Gweler y screenshot:
Excel addin: allforio sawl taflen i ffeiliau testun

2. Yn y blwch deialog agoriadol Llyfr Gwaith Hollt, gwnewch fel a ganlyn:
Excel addin: allforio sawl taflen i ffeiliau testun
(1) Gwiriwch y taflenni gwaith y byddwch chi'n eu hallforio i ffeiliau testun ar wahân yn y Enw'r llyfr gwaith adran;
(2) Gwiriwch y Nodwch fformat arbed opsiwn, ac yna dewiswch y Testun Unicode (* .txt) o'r isod gwymplen, gweler y screenshot chwith:
(3) Cliciwch y Hollti botwm.

3. Ac yna yn y blwch deialog Pori For Folder, dewiswch y ffolder cyrchfan y byddwch chi'n arbed ffeiliau testun wedi'i allforio iddo, a chliciwch ar y OK botwm.

Hyd yn hyn mae pob taflen waith benodol wedi'i hallforio fel ffeil testun ar wahân a'i chadw i'r ffolder penodedig.

Kutools ar gyfer Excel - Supercharge Excel gyda dros 300 o offer hanfodol. Mwynhewch dreial 30 diwrnod llawn sylw AM DDIM heb fod angen cerdyn credyd! Get It Now

Hawdd arbed pob dalen fel ffeil PDF / text / csv ar wahân neu lyfr gwaith yn Excel

Fel arfer gallwn arbed taflen waith weithredol fel ffeil .pdf ar wahân, ffeil .txt, neu ffeil .csv gyda'r nodwedd Cadw Fel. Ond Kutools ar gyfer Excel's Llyfr Gwaith Hollti gall cyfleustodau eich helpu i arbed pob llyfr gwaith yn hawdd fel ffeil neu lyfr gwaith PDF / TEXT / CSV ar wahân yn Excel.


llyfr gwaith rhaniad ad pdf 1

Kutools ar gyfer Excel - Supercharge Excel gyda dros 300 o offer hanfodol. Mwynhewch dreial 30 diwrnod llawn sylw AM DDIM heb fod angen cerdyn credyd! Get It Now


Demo: allforio data Excel (dewis neu daflenni) i ffeiliau Testun yn Excel


Kutools ar gyfer Excel: Dros 300 o offer defnyddiol ar flaenau eich bysedd! Dechreuwch eich treial am ddim 30 diwrnod heb unrhyw gyfyngiadau nodwedd heddiw. Lawrlwytho Nawr!

Erthyglau cysylltiedig:

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
Comments (19)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
How would I amend the code for Export selection (or one column) to text file with VBA to autofill the filename with the contents of cell B2?
thanks
This comment was minimized by the moderator on the site
Hi,This is great, thanks a lot.
How would I alter the code for Export selection (or one column) to text file with VBA to auto fill the filename with the contents of cell B2?
This comment was minimized by the moderator on the site
Hi, this code is very useful for me. So thank you very much.
I want to ask that: When i'm using this code, a new line append automatically at the end of the txt content.
Can you help me about preventing this by vba?
This comment was minimized by the moderator on the site
hi guys, i used that code:
Sub ExportRangetoFile()
'Update 20130913
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

and have working, but i need to savea column with cells that contain the function"concatenate", and when i play the vba code, and i save the .TXT file, only what appears it's #REF. how can i to fix it? cause i need the data that appears on that cells?
This comment was minimized by the moderator on the site
Has anyone been able to figure this out? I am having the same issue.
This comment was minimized by the moderator on the site
HELLO
THANK YOU FOR YOUR VBA CODE
SOMETIMES ON CERTAIN TEXT THERE IS "TEXT" IN EXPORT .TXT
THANK YOU FOR WHY
This comment was minimized by the moderator on the site
Thanks for the awesome piece of VBA code to export data to a text file. I have used your code with some of my own. The data I am dealing with is extremely line-length specific and after the macro has run, the text file contains some double quotation marks " at random places, which was never present in my data before. I have tried adding a code line to remove this character at various stages but that does not seem to be working. I am aware that I can manually remove this but would like to resolve it in the VBA code.

Sub Macro3()
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
Selection.AutoFilter
ActiveSheet.Range("$A$1:$B$10591").AutoFilter Field:=1, Criteria1:= _
"=NSZAP*", Operator:=xlAnd
Range("A1").Select
ActiveCell.Offset(200, 0).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Rows("1:10101").EntireRow.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.AutoFilter
Range(Selection, Selection.End(xlDown)).Select
Set WorkRng = Application.Selection
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
Selection.Replace What:="""", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
Selection.Replace What:="""", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
Selection.Replace What:="""", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi Harish,
For removing a specified character in bulk, you can replace the character with nothing.
Ctrl + H to open the Find and Replace dialog box, type the specified character in the Find what box, and type noting in the replace with box.
This comment was minimized by the moderator on the site
3/2 You might also note that you don't need to specify the wb prefix once you've .Add ed the workbook since it becomes active. Specifying wb might or might not be more efficient but it can be omitted from some commands. Actually I entirely scrapped the variable wb; I just go Workbooks.Add, and use ActiveWorkbook when needed. (As you are suppressing ScreenUpdating it wouldn't be obvious to some that wb is Active. Tip for beginners (and higher): I always, always develop with ScreenUpdating and DisplayAlerts as True, and when done with development, I consider toggling them off for some passage of code.)
This comment was minimized by the moderator on the site
2/2 - vbYesNoCancel msgboxes and Booleans to indicate whether to export all, selection, or a user specified range - a static String for the prior range address - if len(that static)1 then I set WorkRng=activesheet.UsedRange (You can't copy multiple areas with a single copy, though with a little work you could walk the areas and copy them piecemeal.) - Idiotic Microsoft does not save off empty rows at the start and the bottom of the saved range, and does not save off empty columns at the leftmost and the rightmost of the saved range. When I detect that (UsedRange is not row 1, col. 1, or xlLastCell is not completely lower-right) I msgbox to ask user if they want to plug A1 or the lower right cell. - Then I decided to preemptively address the upper left issue by inserting a row and setting A1 to be text like "The following is for range " - I close with activeworkbook.close SaveChanges:=False - Long time habit since I'm an angry proponent of cleaning up (and the world is a sad place thanks to irresponsible programmers who shirk that responsibility when it matters), I set WorkRng = Nothing on the way out :)
This comment was minimized by the moderator on the site
1/2 (since your software limits comment length) I am a serious coder and I want to inform you that the VBA code here is outstanding. It's clean, and not one line too much, or one too few. It's exemplary coding for demonstration of the process. I'll also mention that as I extensively researched solutions for export of selection, you and only one other person suggested dropping the range into a temp new workbook. All other answers were painfully manually, walking through cell by cell. Even Chip's code is much longer and runs slower (but intentionally so, as it is much more flexible - specifiable delimiters, etc.) Just for your amusement, I made some very minor tweaks but otherwise nearly lifted the code word for word because it basically dropped right into a very intricate and specialized application. Some of these tweaks are something I'm sure you do in practice, but they add lines of code (e.g. error checking) so showing them on this webpage would have muddied your display so that the essential elements of processing would have been cumbersome for readers to follow along. Anyway: (see part 2)
This comment was minimized by the moderator on the site
My query is as mentioned below: I have a report to generate everyday. The data what I get on the final row (only one row but more than one columns) I want it to export to another excel sheet which is a summary excel sheet saved separately on my desktop. Eg: Day1 report - final row export to Summary excel sheet row1 Day2 report - final row export to Summary excel sheet row2 Day3 report - final row export to Summary excel sheet row3 and so on.. Export should be done through a click button., which means when I click on export button the data on the sheet I calculated today should go and save on the Summary excel sheet row1, next day a new excel sheet report calculated should go and save on the Summary excel sheet row2 and so on.. Will this be possible to do... If yes please someone help me on this... Thank you in advance...:-)
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations