Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Exporting to Notepad

I am trying to get excel to export a column to a .txt file is there any way that I can do this so that later on I can refrence this file later on. I know I can copy and paste the colmun but I was hoping that there was a way that I could export it..

Thank

Adam Kozul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Exporting to Notepad

I got the following code from this NG. This code assumes the data begins at
A1. I don't recall who to credit, but here's the code:

Public Sub ExportToTextFile()
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String
Dim FName As String
Dim Sep As String
Dim SelectionOnly As Boolean
FName = "testing.txt"
Sep = ","
SelectionOnly = True

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile

If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
End If

Open FName For Output Access Write As #FNum

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = _
Application.WorksheetFunction.Text _
(Cells(RowNdx, ColNdx).Value, _
Cells(RowNdx, ColNdx).NumberFormat)
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum

End Sub


--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winne the Pooh

"Adam Kozul" wrote in message
...
I am trying to get excel to export a column to a .txt file is there any

way that I can do this so that later on I can refrence this file later on.
I know I can copy and paste the colmun but I was hoping that there was a way
that I could export it...

Thanks

Adam Kozul



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Exporting to Notepad

Here is where you got most of it:

http://www.cpearson.com/excel/imptext.htm import/export text files
Chip Pearson's site.

--
Regards,
Tom Ogilvy

"Michael Malinsky" wrote in message
...
I got the following code from this NG. This code assumes the data begins

at
A1. I don't recall who to credit, but here's the code:

Public Sub ExportToTextFile()
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String
Dim FName As String
Dim Sep As String
Dim SelectionOnly As Boolean
FName = "testing.txt"
Sep = ","
SelectionOnly = True

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile

If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
End If

Open FName For Output Access Write As #FNum

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = _
Application.WorksheetFunction.Text _
(Cells(RowNdx, ColNdx).Value, _
Cells(RowNdx, ColNdx).NumberFormat)
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum

End Sub


--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winne the Pooh

"Adam Kozul" wrote in message
...
I am trying to get excel to export a column to a .txt file is there any

way that I can do this so that later on I can refrence this file later on.
I know I can copy and paste the colmun but I was hoping that there was a

way
that I could export it...

Thanks

Adam Kozul





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Exporting to Notepad

Adam

Here's a little easier macro to follow - not as powerful, but for your
specific request, it gets the job done.

Sub Col1ToText()

'copy sheet1 into a new workbook
ThisWorkbook.Sheets(1).Copy

'The new workbook will be active
With ActiveWorkbook

'Delete all the columns but one
.Sheets(1).Columns("B:IV").Delete

'Save the new workbook as text
.SaveAs "C:\Dick\MyCol1.txt", xlTextWindows

'Close the new workbook with no prompt
.Close False
End With

End Sub
--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Adam Kozul" wrote in message
...
I am trying to get excel to export a column to a .txt file is there any

way that I can do this so that later on I can refrence this file later on.
I know I can copy and paste the colmun but I was hoping that there was a way
that I could export it...

Thanks

Adam Kozul



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting to excel from NotePad Hardeep_kanwar[_2_] Excel Worksheet Functions 2 October 11th 08 11:40 PM
Exporting Excel file into Notepad with column & row lines JIVL Charts and Charting in Excel 1 August 26th 08 12:14 AM
Pasting from Notepad Al Excel Discussion (Misc queries) 1 June 14th 05 02:41 AM
Output to Notepad Neil[_14_] Excel Programming 1 January 13th 04 03:10 AM
DDEInitiate with Notepad Kevin Excel Programming 4 October 15th 03 08:35 PM


All times are GMT +1. The time now is 02:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"