メインコンテンツへスキップ

Excelデータ(選択またはシート)をExcelのテキストファイルにエクスポートするにはどうすればよいですか?

ワークブックをテキストファイル形式で配信する必要がある場合は、ワークブックをテキストファイルに変換する必要があります。 また、この記事では、Excelデータをテキストファイルに簡単にエクスポートするXNUMXつの方法を紹介します。

XNUMX枚のシートをExcelのテキストファイルにエクスポートする

デフォルトでは、Excelデータは次の形式でブックとして保存されます。 。XLSX。 ただし、既存のワークブックのワークシートをテキストファイルとしてエクスポートできます。 名前を付けて保存 特徴。 次のようにしてください。

1. テキストファイルにエクスポートするワークシートに移動し、をクリックします File (または Officeボタン)> 名前を付けて保存.

2. オープニング 名前を付けて保存 ダイアログボックスで、エクスポートされたテキストファイルを保存する宛先フォルダを選択し、ファイルに名前を付けます。 ファイル名 ボックスをクリックし、 Unicodeテキスト (* .txt)から タイプとして保存 ドロップダウンリスト。 スクリーンショットを参照してください:
名前を付けて保存機能を使用してテキストファイルにエクスポート

3. 次に、アクティブなワークシートのみをテキストファイルとしてエクスポートし、テキストファイルと互換性のない機能を除外するように求めるXNUMXつの警告ダイアログボックスが表示されます。 クリック OK ボタンと 有り 続けてボタン。

次に、アクティブなワークシートのデータが新しいテキストファイルとしてエクスポートされます。

Note名前を付けて保存 コマンドは、アクティブなワークシートのデータをテキストファイルとしてのみエクスポートできます。 ワークブック全体のすべてのデータをエクスポートする場合は、各ワークシートを個別にテキストファイルとして保存する必要があります。


選択範囲(またはXNUMX列)をVBAを使用してテキストファイルにエクスポートします

次のVBAコードは、選択した範囲データ(XNUMX列など)をテキストファイルにエクスポートするのにも役立ちます。次のようにしてください。

1. 押したまま Alt + F11 キー、そしてそれは開きます アプリケーション向け Microsoft Visual Basic 窓。

2. インセット > モジュール、モジュールウィンドウに次のコードを貼り付けます。

VBA:選択範囲またはワークシート全体をテキストファイルにエクスポートします

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. 次に、 F5 このコードを実行するためのキー。 次に、ポップアップダイアログボックスでエクスポートするデータ範囲を選択し、[ OK ボタン、スクリーンショットを参照してください:
テキストファイルとしてエクスポートする列をXNUMXつ選択します

4. 次に、別の[名前を付けて保存]ダイアログボックスで、このテキストファイルの名前と、このファイルを配置するフォルダーを指定して、[ Save


Kutools for Excelを使用して、選択範囲(またはXNUMX列)をテキストファイルにエクスポートします

  名前を付けて保存 コマンドは、アクティブなワークシート内のすべてのデータをテキストとしてエクスポートできます。 指定された非アクティブなワークシートのすべてのデータ、またはワークシート内のデータの一部をテキストファイルとしてエクスポートするとどうなりますか? Excel用のKutools's 範囲をファイルにエクスポート ユーティリティを使用すると、選択したデータをテキストファイルとして簡単にエクスポートして保存できます。  

Kutools for Excel - Excel に必要な 300 以上のツールが詰め込まれています。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 ダウンロード中!

1. テキストファイルにエクスポートする範囲を選択し(この場合、列Aを選択します)、をクリックします。 クツールズプラス > インポート・エクスポート > 範囲をファイルにエクスポート、スクリーンショットを参照してください:
Excelアドイン:選択範囲をテキストファイルにエクスポート

2. 範囲をファイルにエクスポート ダイアログボックス、以下のスクリーンショットのように実行します。
Excelアドイン:選択範囲をテキストファイルにエクスポート
(1)確認してください Unicodeテキスト 内のオプション ファイル形式 セクション;
(2)[テキストオプション]セクションで、必要に応じて[実際の値を保存する]オプションまたは[画面に表示されているとおりに値を保存する]オプションをオンにします。
(3)エクスポートしたテキストファイルを保存する宛先フォルダを指定します。
(4)クリックします Ok

3. エクスポートしたテキストファイルに新しい開始ダイアログボックスで名前を付け、[ Ok
エクスポートされたテキストファイルに名前を付ける

次に、選択範囲(選択した列A)がテキストファイルとしてエクスポートされ、指定したフォルダーに保存されます。

Kutools for Excel - 300 以上の必須ツールで Excel を強化します。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 今すぐ入手


Excelで複数のシートを個別のテキストファイルにエクスポートする

複数のワークシートをExcelの複数のテキストファイルにエクスポートする必要がある場合があります。 名前を付けて保存機能は少し面倒かもしれません! 心配しないでください! Excel用のKutools 分割ワークブック ユーティリティは、Excelユーザーに、複数のワークシートを数回クリックするだけで多くの個別のテキストファイルにエクスポートするための簡単な回避策を提供します。 

Kutools for Excel - Excel に必要な 300 以上のツールが詰め込まれています。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 ダウンロード中!

1。 クリック クツールズプラス > ワークブック分割ワークブック。 スクリーンショットを参照してください:
Excelアドイン:複数のシートをテキストファイルにエクスポート

2. [ワークブックの分割]ダイアログボックスを開いて、次のようにします。
Excelアドイン:複数のシートをテキストファイルにエクスポート
(1)エクスポートするワークシートをチェックして、 ブック名 セクション;
(2)確認してください 保存形式を指定します オプションを選択し、次に Unicodeテキスト(* .txt) 下のドロップダウンリストから、左のスクリーンショットを参照してください。
(3)をクリックします スプリット

3.次に、ポップアップする[フォルダの参照]ダイアログボックスで、エクスポートされたテキストファイルを保存する宛先フォルダを選択し、[ OK

これまでのところ、指定された各ワークシートは個別のテキストファイルとしてエクスポートされ、指定されたフォルダーに保存されています。

Kutools for Excel - 300 以上の必須ツールで Excel を強化します。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 今すぐ入手

各シートを個別のPDF /テキスト/ csvファイルまたはExcelのワークブックとして簡単に一括保存できます

通常、[名前を付けて保存]機能を使用して、アクティブなワークシートを個別の.pdfファイル、.txtファイル、または.csvファイルとして保存できます。 しかし、Excel用のKutools 分割ワークブック ユーティリティを使用すると、各ワークブックを個別のPDF / TEXT / CSVファイルまたはExcelのワークブックとして簡単に保存できます。


広告分割ワークブックpdf1

Kutools for Excel - 300 以上の必須ツールで Excel を強化します。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 今すぐ入手


デモ:Excelデータ(選択またはシート)をExcelのテキストファイルにエクスポートする


Kutools for Excel: 300 を超える便利なツールをすぐに利用できます。 機能制限なしの 30 日間の無料トライアルを今すぐ始めてください。 今すぐダウンロード!

関連記事:

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
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