Ga naar hoofdinhoud

Hoe Excel-gegevens (selectie of werkbladen) exporteren naar tekstbestanden in Excel?

Als u een werkmap in de indeling van een tekstbestand moet aanleveren, moet u de werkmap naar tekstbestanden converteren. En dit artikel introduceert twee methoden om Excel-gegevens eenvoudig naar tekstbestanden te exporteren.

Exporteer een enkel blad naar een tekstbestand in Excel

Standaard worden de Excel-gegevens opgeslagen als werkmappen in de indeling . Xlsx. We kunnen echter een werkblad van een bestaande werkmap exporteren als tekstbestanden met de extensie Opslaan als voorzien zijn van. Ga als volgt te werk:

1. Ga naar het werkblad dat u naar een tekstbestand wilt exporteren en klik op Dien in (of Office-knop)> Opslaan als.

2. In de opening Opslaan als dialoogvenster, selecteer de doelmap waarin u het geëxporteerde tekstbestand wilt opslaan, geef het bestand een naam in de Bestandsnaam box en selecteer vervolgens het Unicode-tekst (* .txt) uit het Opslaan als type keuzelijst. Zie screenshot:
exporteren naar tekstbestand met de functie Opslaan als

3. Vervolgens verschijnen er twee waarschuwingsdialoogvensters waarin u wordt gevraagd alleen het actieve werkblad als tekstbestand te exporteren en eventuele incompatibele functies met een tekstbestand weg te laten. Klik OK knop en Ja knop achtereenvolgens.

Vervolgens worden de gegevens in het actieve werkblad geëxporteerd als een nieuw tekstbestand.

Note: de Opslaan als commando kan alleen gegevens van een actief werkblad exporteren als een tekstbestand. Als u alle gegevens van de hele werkmap wilt exporteren, moet u elk werkblad afzonderlijk als een tekstbestand opslaan.


Exporteer selectie (of één kolom) naar tekstbestand met VBA

De volgende VBA-code kan u ook helpen om de geselecteerde bereikgegevens (bijvoorbeeld één kolom) naar het tekstbestand te exporteren, doe dit als volgt:

1. Houd de toets ingedrukt ALT + F11 toetsen, en het opent de Microsoft Visual Basic voor toepassingen venster.

2. Klik Invoegen > Moduleen plak de volgende code in het modulevenster.

VBA: export selectie of volledig werkblad naar tekstbestand

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. Druk vervolgens op F5 sleutel om deze code uit te voeren. En selecteer vervolgens het gegevensbereik dat u wilt exporteren in het pop-upvenster en klik op de OK knop, zie screenshot:
Selecteer een kolom om als tekstbestand te exporteren

4. En geef nu in een ander Opslaan als-dialoogvenster een naam op voor dit tekstbestand en een map om dit bestand in te plaatsen, en klik op de Bespaar knop.


Exporteer selectie (of één kolom) naar tekstbestand met Kutools voor Excel

De Opslaan als commando kan alle gegevens in het actieve werkblad als tekst exporteren. Wat gebeurt er als alle gegevens van opgegeven inactieve werkbladen of een deel van de gegevens in een werkblad als een tekstbestand worden geëxporteerd? Kutools voor Excel's Bereik exporteren naar bestand hulpprogramma kan ons helpen bij het exporteren en opslaan van de geselecteerde gegevens als een tekstbestand.  

Kutools for Excel - Verpakt met meer dan 300 essentiële tools voor Excel. Geniet van een GRATIS proefperiode van 30 dagen zonder creditcard! Download nu!

1. Selecteer het nummer dat u naar een tekstbestand wilt exporteren (in ons geval selecteren we kolom A) en klik op Koetools Plus > Import / Export > Bereik exporteren naar bestand, zie screenshot:
Excel addin: export selectie naar tekstbestand

2. In het Bereik exporteren naar bestand dialoogvenster, doe zoals hieronder afgebeeld:
Excel addin: export selectie naar tekstbestand
(1) Controleer het Unicode-tekst optie in het bestandsformaat sectie;
(2) Vink de optie Bewaar de werkelijke waarden aan of Bewaar waarden zoals getoond op het scherm optie zoals je nodig hebt in de Tekst opties sectie;
(3) Specificeer de doelmap waarin u het geëxporteerde tekstbestand wilt opslaan;
(4) Klik op het Ok knop.

3. Geef het geëxporteerde tekstbestand een naam in het nieuwe openingsdialoogvenster en klik op het Ok knop.
geef het geëxporteerde tekstbestand een naam

En dan is de selectie (geselecteerde kolom A) geëxporteerd als een tekstbestand en opgeslagen in de opgegeven map.

Kutools for Excel - Geef Excel een boost met meer dan 300 essentiële tools. Geniet van een GRATIS proefperiode van 30 dagen zonder creditcard! Snap het nu


Exporteer meerdere bladen naar afzonderlijke tekstbestanden in Excel

Soms moet u meerdere werkbladen exporteren naar meerdere tekstbestanden in Excel. De functie Opslaan als kan een beetje vervelend zijn! Maak je geen zorgen! Kutools voor Excel's Werkmap splitsen hulpprogramma biedt Excel-gebruikers een gemakkelijke oplossing om meerdere werkbladen met enkele klikken naar veel afzonderlijke tekstbestanden te exporteren. 

Kutools for Excel - Verpakt met meer dan 300 essentiële tools voor Excel. Geniet van een GRATIS proefperiode van 30 dagen zonder creditcard! Download nu!

1. klikken Koetools Plus > werkboekWerkmap splitsen. Zie screenshot:
Excel-addin: exporteer meerdere bladen naar tekstbestanden

2. Ga als volgt te werk in het dialoogvenster Werkboek splitsen openen:
Excel-addin: exporteer meerdere bladen naar tekstbestanden
(1) Controleer de werkbladen die u naar afzonderlijke tekstbestanden in het Werkmapnaam sectie;
(2) Controleer het Geef het opslagformaat op optie en selecteer vervolgens de Unicode-tekst (* .txt) van onderstaande vervolgkeuzelijst, zie linker screenshot:
(3) Klik op het Split knop.

3. Selecteer vervolgens in het dialoogvenster Bladeren naar map de doelmap waarin u de geëxporteerde tekstbestanden wilt opslaan en klik op de knop OK knop.

Tot nu toe is elk gespecificeerd werkblad geëxporteerd als een afzonderlijk tekstbestand en opgeslagen in de gespecificeerde map.

Kutools for Excel - Geef Excel een boost met meer dan 300 essentiële tools. Geniet van een GRATIS proefperiode van 30 dagen zonder creditcard! Snap het nu

Sla elk blad eenvoudig massaal op als een afzonderlijk pdf- / tekst- / csv-bestand of werkmap in Excel

Normaal gesproken kunnen we een actief werkblad opslaan als een afzonderlijk .pdf-bestand, .txt-bestand of .csv-bestand met de functie Opslaan als. Maar Kutools voor Excel's Werkmap splitsen hulpprogramma kan u helpen elke werkmap eenvoudig op te slaan als afzonderlijk PDF / TEXT / CSV-bestand of werkmap in Excel.


ad split werkmap pdf 1

Kutools for Excel - Geef Excel een boost met meer dan 300 essentiële tools. Geniet van een GRATIS proefperiode van 30 dagen zonder creditcard! Snap het nu


Demo: exporteer Excel-gegevens (selectie of bladen) naar tekstbestanden in Excel


Kutools for Excel: Ruim 300 handige tools binnen handbereik! Start vandaag nog uw gratis proefperiode van 30 dagen zonder functiebeperkingen. Nu downloaden!

Gerelateerde artikelen:

Beste Office-productiviteitstools

🤖 Kutools AI-assistent: Een revolutie teweegbrengen in de data-analyse op basis van: Intelligente uitvoering   |  Genereer code  |  Aangepaste formules maken  |  Analyseer gegevens en genereer grafieken  |  Roep Kutools-functies aan...
Populaire functies: Zoek, markeer of identificeer duplicaten   |  Verwijder lege rijen   |  Combineer kolommen of cellen zonder gegevens te verliezen   |   Ronde zonder formule ...
Super opzoeken: Meerdere criteria VLookup    VLookup met meerdere waarden  |   VOpzoeken over meerdere bladen   |   Fuzzy opzoeken ....
Geavanceerde vervolgkeuzelijst: Maak snel een vervolgkeuzelijst   |  Afhankelijke vervolgkeuzelijst   |  Multi-select vervolgkeuzelijst ....
Kolom Beheerder: Voeg een specifiek aantal kolommen toe  |  Kolommen verplaatsen  |  Schakel de zichtbaarheidsstatus van verborgen kolommen in  |  Vergelijk bereiken en kolommen ...
Uitgelichte functies: Raster focus   |  Ontwerpweergave   |   Grote formulebalk    Werkmap- en bladbeheer   |  resource Library (Auto-tekst)   |  Datumkiezer   |  Combineer werkbladen   |  Cellen coderen/decoderen    Stuur e-mails per lijst   |  Super filter   |   Speciaal filter (filter vet/cursief/doorhalen...) ...
Top 15 gereedschapsets12 Tekst Tools (toe te voegen tekst, Tekens verwijderen, ...)   |   50+ tabel Types (Gantt Chart, ...)   |   40+ Praktisch Formules (Bereken leeftijd op basis van verjaardag, ...)   |   19 Invoeging Tools (QR-code invoegen, Afbeelding invoegen vanaf pad, ...)   |   12 Camper ombouw Tools (Getallen naar woorden, Currency Conversion, ...)   |   7 Samenvoegen en splitsen Tools (Geavanceerd Combineer rijen, Gespleten cellen, ...)   |   ... en meer

Geef uw Excel-vaardigheden een boost met Kutools voor Excel en ervaar efficiëntie als nooit tevoren. Kutools voor Excel biedt meer dan 300 geavanceerde functies om de productiviteit te verhogen en tijd te besparen.  Klik hier om de functie te krijgen die u het meest nodig heeft...

Omschrijving


Office-tabblad Brengt een interface met tabbladen naar Office en maakt uw werk veel gemakkelijker

  • Schakel bewerken en lezen met tabbladen in Word, Excel, PowerPoint in, Publisher, Access, Visio en Project.
  • Open en maak meerdere documenten in nieuwe tabbladen van hetzelfde venster in plaats van in nieuwe vensters.
  • Verhoogt uw productiviteit met 50% en vermindert honderden muisklikken voor u elke dag!
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