View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
pieros pieros is offline
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file

On Jan 12, 1:05 pm, "kounoike" wrote:
I might be wrong, but in my guess, you seem to forget to close the output
file when exit sub, so data in a file buffer was'nt written into output
file.

Do While Not Cells(RowNdx, ColNdx) = "" 'Voer uit t/m de laatste
met tekst gevulde regel van het file
Print #1, Cells(RowNdx, ColNdx).Value 'schrijf regel naar file
RowNdx = RowNdx + 1 'Volgende regel
Loop


close #1 ' i think you need to close file here



End Sub


keizi

"pieros" wrote in message

oups.com...





NickHK,


- The Cells refer indeed to the same worksheet in both routines.


- I am sure Cells(RowNdx, ColNdx) = "" does evaluate TRUE at line 100.
The first empty cell is A112 and the RowNdx stops counting here. So
that's working correctly.


- I am resetting the RowNdx before the second loop.


- I am sure all the data is read correctly in the first column.


I send you my total code.
(This code is only a test. If this works fine I will go on for all my
files. It is at the same time good for me to practice so I later can do
more with VBA).


Here is my code:
Option Explicit


'*********************** Programma schrijft alleen de 1e 100 regels
naar het aangegeven file - de laatste regel niet helemaal compleet
??????? **


Sub read_file()


Dim strTemp As String
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim Line1 As String


RowNdx = 1 'Beginnen in 1e regel
ColNdx = 1 'Beginnen in 1e kolom


Close #1 'Sluit file nr. 1


Open "U:\Programs - Documents\MSExcel\Test zoek en vervang 4 - mee
bezig\Approved\Cop00004500\00004583_001_KART_KM9_V 1.xml" For Input As
#1


Do While Not EOF(1) 'Voer uit t/m de laatste regel van het file
Line Input #1, strTemp 'Lees regel
Cells(RowNdx, ColNdx).Value = strTemp 'schrijf regel naar
Excel-sheet
RowNdx = RowNdx + 1 'Volgende regel
Loop


Line1 = Mid(Cells(1, 1), 3, 21)
Cells(1, 1).Value = Line1 'schrijf regel naar Excel-sheet


Close #1 'Sluit file nr. 1


Range("A1").Select
Cells.Replace What:="1LS-Arial", Replacement:="1LS-OCR-B-10 BT",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False


RowNdx = 1 'Beginnen in 1e regel
ColNdx = 1 'Beginnen in 1e kolom


MkDir "U:\Programs - Documents\MSExcel\Test zoek en vervang 4 - mee
bezig\Corrected\Cop00004500\"


Close #1 'Sluit file nr. 1


Open "U:\Programs - Documents\MSExcel\Test zoek en vervang 4 - mee
bezig\Corrected\Cop00004500\00004583_001_KART_KM9_ V1.xml" For Output As
#1


Do While Not Cells(RowNdx, ColNdx) = "" 'Voer uit t/m de laatste
met tekst gevulde regel van het file
Print #1, Cells(RowNdx, ColNdx).Value 'schrijf regel naar file
RowNdx = RowNdx + 1 'Volgende regel
Loop


End Sub


Thanks for your response,
Pieros- Hide quoted text -


- Show quoted text -


You are right!! I forgot to close.
All seems to work well but now I saw that the Euro character in my
input file became a wrong unreadable character in my output file.
I don't know what the reason is. It happens during the writing of the
excel lines to the output file. ??????

Pieros.