Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Problem with txt

Nuno,

Better to control exactly what gets written to the file using a macro. See
an example below.

HTH,
Bernie
MS Excel MVP

Sub ExportToTXT()

Dim FName As String
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

FName = "C:\Excel\ExportText.txt"

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

With Range("A2").CurrentRegion
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With

Open FName For Output Access Write As #FNum

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
WholeLine = WholeLine & " """ & _
Cells(RowNdx, ColNdx).Text & """ "
Next ColNdx
Print #FNum, WholeLine
Next RowNdx

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


End Sub



"Nuno" wrote in message
...
Hi everyone!

I was wondering if you cound help with a problem I'm having with Excel. I
have a list of codes that I want Excel to save in txt format with the "".
I'll explain: I have thousands of codes in a numerical format (e.g.

3173471;
3174742, etc.) but I need to save a txt file that puts "" around the

value,
i.e., "3173471", "3174742", etc. I've tried to use the concatenate

function,
replace and even tried to program a macro (I'm not that proficient in

macros,
so something could be wrong...) but nothing worked. The best i could was
using the replace function and, in fact, in Excel it looked as if

everything
was correct, i.e., i saw "3174742", . However, when I saved it to txt I

got
this weird result: """3174742""". I could try to make the replacement in

word
or notepad, but given the huge amount of files I'm using this would be to
cumbersome.
Does anyone has an idea how I could get around this?

Cheers,

Nuno



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
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
problem with a conditional max problem Brian Cornejo Excel Discussion (Misc queries) 1 February 18th 05 06:25 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


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

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"