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.
|