PC Review


Reply
Thread Tools Rate Thread

Comma Delimited Export

 
 
Mike Kiekover
Guest
Posts: n/a
 
      8th Mar 2007
I use the following macro to export data in a comma delimeted fashion as
opposed to save as .csv due to necessary quotation marks in the data cells.
This works great, except that I have to do a SAVE AS on the file before the
macro will function. Just a SAVE doesn't do it either. Once I SAVE AS to the
same name, the macro works for as long as I have the file open. But if I
close Excel and re-open the macro doesn't populate the destination file. I
tested the macro on a blank workbook as well with the same results, so it
doesn't seem to be file related.

Can anyone see anything that would change this, and allow me to open the
file and run the macro without the "save as" step.

**************
Public Sub TextNoModification()
Const DELIMITER As String = "," 'or "|", vbTab, etc.
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "isogen_atts.att" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, Columns.Count).End(xlToLeft))
sOut = sOut & DELIMITER & myField.Text
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub
***************



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
 
Mike Kiekover
Guest
Posts: n/a
 
      8th Mar 2007
One thing that does work for me is to add the "Save-As" in the macro.
However, this file will be used as a template and saved with different names
and paths. Is there a way to change the path in the following string to
force a "Save-As" to the current file name and path.

************
ActiveWorkbook.SaveAs Filename:= _
"Q:\COP\06-243 FCC Energy Recovery Detailed\ENGINEER\Lists\PN
2005044 Piping Line List Rev 0.xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
************



"Mike Kiekover" <(E-Mail Removed)> wrote in message
news:45f07112$0$16393$(E-Mail Removed)...
>I use the following macro to export data in a comma delimeted fashion as
>opposed to save as .csv due to necessary quotation marks in the data cells.
>This works great, except that I have to do a SAVE AS on the file before the
>macro will function. Just a SAVE doesn't do it either. Once I SAVE AS to
>the same name, the macro works for as long as I have the file open. But if
>I close Excel and re-open the macro doesn't populate the destination file.
>I tested the macro on a blank workbook as well with the same results, so it
>doesn't seem to be file related.
>
> Can anyone see anything that would change this, and allow me to open the
> file and run the macro without the "save as" step.
>
> **************
> Public Sub TextNoModification()
> Const DELIMITER As String = "," 'or "|", vbTab, etc.
> Dim myRecord As Range
> Dim myField As Range
> Dim nFileNum As Long
> Dim sOut As String
>
> nFileNum = FreeFile
> Open "isogen_atts.att" For Output As #nFileNum
> For Each myRecord In Range("A1:A" & _
> Range("A" & Rows.Count).End(xlUp).Row)
> With myRecord
> For Each myField In Range(.Cells(1), _
> Cells(.Row, Columns.Count).End(xlToLeft))
> sOut = sOut & DELIMITER & myField.Text
> Next myField
> Print #nFileNum, Mid(sOut, 2)
> sOut = Empty
> End With
> Next myRecord
> Close #nFileNum
> End Sub
> ***************
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>




--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Earl Kiosterud
Guest
Posts: n/a
 
      11th Mar 2007
Mike,

Try the Text Write Program at http://www.smokeylake.com/excel/text_write_program.htm
--
Earl Kiosterud
www.smokeylake.com
-----------------------------------------------------------------------
"Mike Kiekover" <(E-Mail Removed)> wrote in message
news:45f07112$0$16393$(E-Mail Removed)...
>I use the following macro to export data in a comma delimeted fashion as opposed to save as
>.csv due to necessary quotation marks in the data cells. This works great, except that I
>have to do a SAVE AS on the file before the macro will function. Just a SAVE doesn't do it
>either. Once I SAVE AS to the same name, the macro works for as long as I have the file
>open. But if I close Excel and re-open the macro doesn't populate the destination file. I
>tested the macro on a blank workbook as well with the same results, so it doesn't seem to
>be file related.
>
> Can anyone see anything that would change this, and allow me to open the file and run the
> macro without the "save as" step.
>
> **************
> Public Sub TextNoModification()
> Const DELIMITER As String = "," 'or "|", vbTab, etc.
> Dim myRecord As Range
> Dim myField As Range
> Dim nFileNum As Long
> Dim sOut As String
>
> nFileNum = FreeFile
> Open "isogen_atts.att" For Output As #nFileNum
> For Each myRecord In Range("A1:A" & _
> Range("A" & Rows.Count).End(xlUp).Row)
> With myRecord
> For Each myField In Range(.Cells(1), _
> Cells(.Row, Columns.Count).End(xlToLeft))
> sOut = sOut & DELIMITER & myField.Text
> Next myField
> Print #nFileNum, Mid(sOut, 2)
> sOut = Empty
> End With
> Next myRecord
> Close #nFileNum
> End Sub
> ***************
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to comma-delimited format doesn't seem to work Patty Ayers Microsoft Excel Discussion 9 5th May 2008 03:27 PM
export a report to a comma delimited csv file Garry Microsoft Access Reports 0 19th Sep 2007 05:33 PM
Export to comma-delimited truncates numbers after decimal Geoff Microsoft Access 1 1st Mar 2006 07:04 AM
export date without time - comma delimited file Jubejoie@aol.com Microsoft Access Database Table Design 1 4th Jun 2004 01:47 AM
EXPORT EXCEL DATABASE TO A COMMA DELIMITED TEXT FILE =?Utf-8?B?QkZFMzM=?= Microsoft Access External Data 1 28th Oct 2003 06:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:41 PM.