Vai al contenuto principale

Come esportare i dati Excel (selezione o fogli) in file di testo in Excel?

Se è necessario fornire una cartella di lavoro nel formato di file di testo, è necessario convertire la cartella di lavoro in file di testo. E questo articolo ti introdurrà due metodi per esportare facilmente i dati di Excel in file di testo.

Esporta un singolo foglio in un file di testo in Excel

Per impostazione predefinita, i dati di Excel verranno salvati come cartelle di lavoro nel formato . Xlsx. Tuttavia, possiamo esportare un foglio di lavoro della cartella di lavoro esistente come file di testo con l'estensione Salva con nome caratteristica. Si prega di fare quanto segue:

1. Passa al foglio di lavoro che esporterai in un file di testo e fai clic Compila il (o Pulsante di ufficio)> Salva con nome.

2. In apertura Salva con nome finestra di dialogo, selezionare la cartella di destinazione in cui salvare il file di testo esportato, assegnare un nome al file in Nome del file casella, quindi seleziona il file Testo Unicode (* .txt) dal file Salva come tipo menu `A tendina. Vedi screenshot:
esportare in un file di testo con la funzione Salva con nome

3. Quindi appariranno due finestre di dialogo di avviso che chiedono di esportare solo il foglio di lavoro attivo come file di testo e di tralasciare eventuali funzionalità incompatibili con il file di testo. Clic OK pulsante e successivamente.

Quindi i dati nel foglio di lavoro attivo vengono esportati come nuovo file di testo.

Note:: il Salva con nome Il comando è in grado di esportare solo i dati del foglio di lavoro attivo come file di testo. Se si desidera esportare tutti i dati dell'intera cartella di lavoro, è necessario salvare singolarmente ogni foglio di lavoro come file di testo.


Esporta la selezione (o una colonna) in un file di testo con VBA

Il seguente codice VBA può anche aiutarti a esportare i dati dell'intervallo selezionato (ad esempio una colonna) nel file di testo, per favore fai come segue:

1. Tenere premuto il tasto ALT + F11 chiavi e apre il file Microsoft Visual Basic, Applications Edition finestra.

2. Clicchi inserire > Modulie incolla il codice seguente nella finestra del modulo.

VBA: esporta la selezione o l'intero foglio di lavoro in un file di testo

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. Quindi premere F5 chiave per eseguire questo codice. Quindi seleziona l'intervallo di dati che desideri esportare nella finestra di dialogo che si apre e fai clic su OK pulsante, vedi screenshot:
Seleziona una colonna da esportare come file di testo

4. E ora in un'altra finestra di dialogo Salva con nome, specificare un nome per questo file di testo e una cartella in cui inserire questo file e fare clic su Risparmi pulsante.


Esporta la selezione (o una colonna) in un file di testo con Kutools per Excel

Le Salva con nome il comando può esportare tutti i dati nel foglio di lavoro attivo come testo. Cosa succede se si esportano tutti i dati di fogli di lavoro inattivi specificati o parte dei dati in un foglio di lavoro come file di testo? Kutools per Excel's Esporta intervallo su file l'utility può aiutarci a esportare e salvare facilmente i dati nella selezione come file di testo.  

Kutools for Excel - Ricco di oltre 300 strumenti essenziali per Excel. Goditi una prova GRATUITA di 30 giorni con tutte le funzionalità senza carta di credito richiesta! Scaricare ora!

1. Seleziona il rang che esporterai in un file di testo (nel nostro caso, selezioniamo la colonna A) e fai clic Kutools Plus > Importa / Esporta > Esporta intervallo su file, vedi screenshot:
Componente aggiuntivo di Excel: esporta la selezione in un file di testo

2. Nel Esporta intervallo su file finestra di dialogo, fai come mostrato nell'immagine sottostante:
Componente aggiuntivo di Excel: esporta la selezione in un file di testo
(1) Controllare il file Testo Unicode opzione nel Formato del file sezione;
(2) Seleziona l'opzione Salva i valori effettivi o Salva i valori come mostrato sullo schermo opzione di cui hai bisogno nella sezione Opzioni di testo;
(3) Specificare la cartella di destinazione in cui salvare il file di testo esportato;
(4) Fare clic su Ok pulsante.

3. Assegnare un nome al file di testo esportato nella nuova finestra di dialogo di apertura e fare clic su Ok pulsante.
denominare il file di testo esportato

E poi la selezione (selezionata Colonna A) è stata esportata come file di testo e salvata nella cartella specificata.

Kutools for Excel - Potenzia Excel con oltre 300 strumenti essenziali. Goditi una prova GRATUITA di 30 giorni con tutte le funzionalità senza carta di credito richiesta! Get It Now


Esporta più fogli per separare file di testo in Excel

A volte potrebbe essere necessario esportare più fogli di lavoro in più file di testo in Excel. La funzione Salva con nome potrebbe essere un po' noiosa! Non preoccuparti! Kutools per Excel Cartella di lavoro divisa L'utilità fornisce agli utenti di Excel una soluzione alternativa semplice per esportare più fogli di lavoro in molti file di testo separati con diversi clic. 

Kutools for Excel - Ricco di oltre 300 strumenti essenziali per Excel. Goditi una prova GRATUITA di 30 giorni con tutte le funzionalità senza carta di credito richiesta! Scaricare ora!

1. Clic Kutools Plus > Cartella di lavoroCartella di lavoro divisa. Vedi screenshot:
Componente aggiuntivo di Excel: esporta più fogli in file di testo

2. Nella finestra di dialogo di apertura della cartella di lavoro divisa, eseguire le seguenti operazioni:
Componente aggiuntivo di Excel: esporta più fogli in file di testo
(1) Controlla i fogli di lavoro che esporterai in file di testo separati nel file Nome cartella di lavoro sezione;
(2) Controllare il file Specifica il formato di salvataggio opzione, quindi selezionare il Testo Unicode (* .txt) dal basso elenco a discesa, vedi screenshot a sinistra:
(3) Fare clic su Diviso pulsante.

3. Quindi, nella finestra di dialogo Sfoglia per cartelle, selezionare la cartella di destinazione in cui salvare i file di testo esportati e fare clic sul pulsante OK pulsante.

Finora ogni foglio di lavoro specificato è stato esportato come file di testo separato e salvato nella cartella specificata.

Kutools for Excel - Potenzia Excel con oltre 300 strumenti essenziali. Goditi una prova GRATUITA di 30 giorni con tutte le funzionalità senza carta di credito richiesta! Get It Now

Salva facilmente in massa ogni foglio come file PDF / testo / csv separato o cartella di lavoro in Excel

Normalmente possiamo salvare il foglio di lavoro attivo come file .pdf, file .txt o file .csv separato con la funzione Salva con nome. Ma Kutools per Excel Cartella di lavoro divisa l'utility può aiutarti a salvare facilmente ogni cartella di lavoro come file PDF / TESTO / CSV separato o cartella di lavoro in Excel.


cartella di lavoro ad split pdf 1

Kutools for Excel - Potenzia Excel con oltre 300 strumenti essenziali. Goditi una prova GRATUITA di 30 giorni con tutte le funzionalità senza carta di credito richiesta! Get It Now


Demo: esporta i dati Excel (selezione o fogli) in file di testo in Excel


Kutools for Excel: Oltre 300 strumenti utili a portata di mano! Inizia oggi la tua prova gratuita di 30 giorni senza limitazioni di funzionalità. Scarica ora!

Articoli Correlati:

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
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