ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Why can't I Export selected cells to tab-delimited text file? (https://www.excelbanter.com/excel-discussion-misc-queries/57562-re-why-cant-i-export-selected-cells-tab-delimited-text-file.html)

JE McGimpsey

Why can't I Export selected cells to tab-delimited text file?
 
This macro is fairly simple to implement:

Public Sub ExportSelectionAsDelimitedFile()
Const sDELIM As String = vbTab
Const sPATH As String = "<your path here"
Const sFILENAME As String = "test.txt"
Dim rArea As Range
Dim rRow As Range
Dim rCell As Range
Dim nFile As Long
Dim sRow As String
If TypeOf Selection Is Range Then
nFile = FreeFile
Open sPATH & sFILENAME For Output As nFile
For Each rArea In Selection.Areas
For Each rRow In rArea.Rows
sRow = ""
For Each rCell In rRow.Cells
sRow = sRow & sDELIM & rCell.Text
Next rCell
Print #nFile, Mid(sRow, Len(sDELIM) + 1)
Next rRow
Next rArea
Close #nFile
End If
End Sub


In article ,
"Lisa B." wrote:

This should be an easy thing to do.

I'd like to set up a "refreshable" text export, in much the same way that
you can set up a "refreshable" text import.

Maybe I'm missing something, but it seems that Excel has little in the way
of Export capability.

Yes, I know there is a slightly more cumbersome way of doing this:
copy - open text file - paste - close text file - click "yes" in save
dialog.

Lisa B.


Dana DeLouis

Why can't I Export selected cells to tab-delimited text file?
 
Don't know if this would help, but another option might be:
File | Save as Web page...
Then check "Selection"

Not quite a "Tab-delimited" file, but it may give you some other ideas to
work with.
Not sure, but there is also Data | Import external data... Perhaps you can
point to your data here.

--
Dana DeLouis
Win XP & Office 2003


"JE McGimpsey" wrote in message
...
This macro is fairly simple to implement:

Public Sub ExportSelectionAsDelimitedFile()
Const sDELIM As String = vbTab
Const sPATH As String = "<your path here"
Const sFILENAME As String = "test.txt"
Dim rArea As Range
Dim rRow As Range
Dim rCell As Range
Dim nFile As Long
Dim sRow As String
If TypeOf Selection Is Range Then
nFile = FreeFile
Open sPATH & sFILENAME For Output As nFile
For Each rArea In Selection.Areas
For Each rRow In rArea.Rows
sRow = ""
For Each rCell In rRow.Cells
sRow = sRow & sDELIM & rCell.Text
Next rCell
Print #nFile, Mid(sRow, Len(sDELIM) + 1)
Next rRow
Next rArea
Close #nFile
End If
End Sub


In article ,
"Lisa B." wrote:

This should be an easy thing to do.

I'd like to set up a "refreshable" text export, in much the same way that
you can set up a "refreshable" text import.

Maybe I'm missing something, but it seems that Excel has little in the
way
of Export capability.

Yes, I know there is a slightly more cumbersome way of doing this:
copy - open text file - paste - close text file - click "yes" in save
dialog.

Lisa B.





All times are GMT +1. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com