Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file

I wonder if someone can help me with this.
I try to read from a text file with this piece of code;

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
(This file is 110 lines long).
And so far is all going well.


But now I have to write all lines to another file (some lines are
modified).
Unfortunately stops the writing at line 100. (Some characters at the
end of line 100 are also missing).
The row counting is going on until the first empty row in the excel
sheet.
I herefor use this code;

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

I don't know why the Print #1-command suddenly stops writing to the
file at line 100????
Can someone help me with this??

Thanks,
Pieros.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default The Print # command print not all rows from excel sheet to file

Pieros,
No reason why print should stop at 100 unless you tell it to stop. Maybe one
of these ?

- I suppose the Cells refer to the same worksheet in both routines, but it
would be better the be clear. e.g.

With Worksheet(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
'Notice the "." before the Cells above

- Are you sure Cells(RowNdx, ColNdx) = "" does not evaluate to true at line
100 ?

- You are resetting RowNdx=0 before the 2 loop ?

-Are you sure all the data is correctly read first ?

Also, it is not a good idea to hardcode file numbers. Use FreeFile instead.
Check the Help

NickHK

"pieros" wrote in message
ups.com...
I wonder if someone can help me with this.
I try to read from a text file with this piece of code;

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
(This file is 110 lines long).
And so far is all going well.


But now I have to write all lines to another file (some lines are
modified).
Unfortunately stops the writing at line 100. (Some characters at the
end of line 100 are also missing).
The row counting is going on until the first empty row in the excel
sheet.
I herefor use this code;

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

I don't know why the Print #1-command suddenly stops writing to the
file at line 100????
Can someone help me with this??

Thanks,
Pieros.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file


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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default The Print # command print not all rows from excel sheet to file

Code looks OK in terms of reading/write.

I can only say that either you data is not what you thing, or the .Replace
is having unexpected effect .

However, it looks like you can avoid using the Excel cells:
Sub read_file()
Dim strTemp As String
Dim InFile As Long
Dim OutFile As Long

InFile = FreeFile
OutFile = FreeFile(200)

Open "C:\dat.txt" For Input As #InFile
Open "C:\outdat.txt" For Output As #OutFile

Do While Not EOF(InFile) 'Voer uit t/m de laatste regel van het file
Line Input #InFile, strTemp 'Lees regel
Print #OutFile, Replace(strTemp, "Find", "Replace")
Loop
'Or you can replace the above loop with
'strTemp = Input(LOF(InFile), #InFile)
'strTemp = Replace(strTemp, "Find", "Replace")
'Print #OutFile, strTemp
'
'Or even
'Print #OutFile, Replace(Input(LOF(InFile), #InFile), "Find", "Replace")

Close #InFile 'Sluit file nr. 1
Close #OutFile 'Sluit file nr. 1

End Sub

NickHK

"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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file

Thanks NickHK, I will try your suggestions. I let you know!!

Pieros.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file


NickHK,

I tried the first part of your code and all I get is the following:
㼼浸敶獲潩㵮ㄢ〮㼢ാ㰊祄慮慍* *潲敪瑣*瑩敬橓扡潬湯㑟洰*扒* *敶獲潩㵮〢ㄮ㸢਍䐼湹浡牡扏敪 瑣*灹㵥䌢扏呪硥ാ㰊佃橢慂敳慄 *浥汰瑡敶獲潩㵮〢ㄮ㸢਍似橢慎 **灹㵥䌢瑓楲杮㸢硅䑰瑡㱥伯橢慎* ാ㰊慐慲*汥祡乳浡祴数千牴湩 䬾き猹慴摮慡摲慐慲*汥祡乳浡㹥 䤼癮牥
The chinese characters I get here are all squares in my "OutFile"
So I do not get the right characters).

Pieros.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file

NickHK,

I also tried the second part with the "strTemp = Input(LOF(InFile),
#InFile)" -line BUT here I get a Runtime error '62': Input past end of
file.
Help?

Pieros


pieros wrote:
NickHK,

I tried the first part of your code and all I get is the following:
㼼浸敶獲潩㵮ㄢ〮㼢ാ㰊祄慮慍* *潲敪瑣*瑩敬橓扡潬湯㑟洰*扒* *敶獲潩㵮〢ㄮ㸢਍䐼湹浡牡扏敪 瑣*灹㵥䌢扏呪硥ാ㰊佃橢慂敳慄 *浥汰瑡敶獲潩㵮〢ㄮ㸢਍似橢慎 **灹㵥䌢瑓楲杮㸢硅䑰瑡㱥伯橢慎* ാ㰊慐慲*汥祡乳浡祴数千牴湩 䬾き猹慴摮慡摲慐慲*汥祡乳浡㹥 䤼癮牥
The chinese characters I get here are all squares in my "OutFile"
So I do not get the right characters).

Pieros.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default The Print # command print not all rows from excel sheet to file

You have Unicode text files ?

Nick

"pieros" wrote in message
oups.com...
NickHK,

I also tried the second part with the "strTemp = Input(LOF(InFile),
#InFile)" -line BUT here I get a Runtime error '62': Input past end of
file.
Help?

Pieros


pieros wrote:
NickHK,

I tried the first part of your code and all I get is the following:

??????????????????????????????????.??????????????? ??????????????????????????
?????????????????????????????????????????????????? ???????????
The chinese characters I get here are all squares in my "OutFile"
So I do not get the right characters).

Pieros.




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file

Good morning NickHK (It now is here about 08:40 am),

My text files are good readable characters. Here is an example:

<?xml version="1.0"?
<DynaMark-Project title="Sjabloon_40mm_Rb.xml" version="0.1"
<Dynamark-Object type="CObjText"
<CObjBaseData template-version="0.1"
<ObjName type="CString"ExpDate</ObjName
<ParamDelaysName type="CString"KM09standaard</ParamDelaysName
<Invers type="bool" value="false"/
<Mark type="bool" value="true"/
<Offset type="CPoint" value="-1908788 -725252"/
<ScaleX type="double" value="1.8"/
<ScaleY type="double" value="2.2"/
<RadiantX type="double" value="-1.5708"/
<RadiantY type="double" value="-1.5708"/
<MirrorX type="bool" value="true"/
<MirrorY type="bool" value="true"/
<LaserNr type="int" value="0"/
<MinVectorLength type="double" value="0"/
<XCenterMode type="int" value="0"/
<YCenterMode type="int" value="0"/</CObjBaseData
<CObjText
<Text type="CString"2222222</Text
<FontName type="CString"1LS-Arial</FontName

And than about 100 - 120 lines for each file.
So there seems nothing wrong with the text.

My goal is to replace the text 1LS-Arial or 1LS-Arial-U in 1LS-OCR-B-10
BT in each file but in some files the text 1LS-OCR-B-10 BT is already
present so needs no modification.

Pieros.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default The Print # command print not all rows from excel sheet to file

I can't repeat your error(s) using this code your XML file.
It replaces fine, no Chinese or errors.

Dim InFile As Long
Dim OutFile As Long

InFile = FreeFile
Open "C:\Replace.txt" For Input As #InFile

OutFile = FreeFile
Open "C:\outdat.txt" For Output As #OutFile

Print #OutFile, Replace(Input(LOF(InFile), #InFile), "1LS-Arial",
"1LS-OCR-B-10 BT")

Close #InFile
Close #OutFile

As for the files, whilst they may be text, they can still be saved in a
Unicode format. Open in NotePad, do a SaveAs and check the Encoding setting.
However, I get different errors to those you mentioned if the file is
Unicode.

NickHK

"pieros" wrote in message
oups.com...
Good morning NickHK (It now is here about 08:40 am),

My text files are good readable characters. Here is an example:

<?xml version="1.0"?
<DynaMark-Project title="Sjabloon_40mm_Rb.xml" version="0.1"
<Dynamark-Object type="CObjText"
<CObjBaseData template-version="0.1"
<ObjName type="CString"ExpDate</ObjName
<ParamDelaysName type="CString"KM09standaard</ParamDelaysName
<Invers type="bool" value="false"/
<Mark type="bool" value="true"/
<Offset type="CPoint" value="-1908788 -725252"/
<ScaleX type="double" value="1.8"/
<ScaleY type="double" value="2.2"/
<RadiantX type="double" value="-1.5708"/
<RadiantY type="double" value="-1.5708"/
<MirrorX type="bool" value="true"/
<MirrorY type="bool" value="true"/
<LaserNr type="int" value="0"/
<MinVectorLength type="double" value="0"/
<XCenterMode type="int" value="0"/
<YCenterMode type="int" value="0"/</CObjBaseData
<CObjText
<Text type="CString"2222222</Text
<FontName type="CString"1LS-Arial</FontName

And than about 100 - 120 lines for each file.
So there seems nothing wrong with the text.

My goal is to replace the text 1LS-Arial or 1LS-Arial-U in 1LS-OCR-B-10
BT in each file but in some files the text 1LS-OCR-B-10 BT is already
present so needs no modification.

Pieros.





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file

I tried your last code to see what happens but I get a Compile Error:
"Wrong number of arguments or invalid property assignment" at the
Replace line. My Excel version is Microsoft Excel 2002. Maybe that's a
problem?

Pieros

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default The Print # command print not all rows from excel sheet to file

This line :
Print #OutFile, Replace(Input(LOF(InFile), #InFile), "1LS-Arial",
"1LS-OCR-B-10 BT")

needs to be all one line. The news reader wrapped it.

NickHK

"NickHK" wrote in message
...
I can't repeat your error(s) using this code your XML file.
It replaces fine, no Chinese or errors.

Dim InFile As Long
Dim OutFile As Long

InFile = FreeFile
Open "C:\Replace.txt" For Input As #InFile

OutFile = FreeFile
Open "C:\outdat.txt" For Output As #OutFile

Print #OutFile, Replace(Input(LOF(InFile), #InFile), "1LS-Arial",
"1LS-OCR-B-10 BT")

Close #InFile
Close #OutFile

As for the files, whilst they may be text, they can still be saved in a
Unicode format. Open in NotePad, do a SaveAs and check the Encoding

setting.
However, I get different errors to those you mentioned if the file is
Unicode.

NickHK

"pieros" wrote in message
oups.com...
Good morning NickHK (It now is here about 08:40 am),

My text files are good readable characters. Here is an example:

<?xml version="1.0"?
<DynaMark-Project title="Sjabloon_40mm_Rb.xml" version="0.1"
<Dynamark-Object type="CObjText"
<CObjBaseData template-version="0.1"
<ObjName type="CString"ExpDate</ObjName
<ParamDelaysName type="CString"KM09standaard</ParamDelaysName
<Invers type="bool" value="false"/
<Mark type="bool" value="true"/
<Offset type="CPoint" value="-1908788 -725252"/
<ScaleX type="double" value="1.8"/
<ScaleY type="double" value="2.2"/
<RadiantX type="double" value="-1.5708"/
<RadiantY type="double" value="-1.5708"/
<MirrorX type="bool" value="true"/
<MirrorY type="bool" value="true"/
<LaserNr type="int" value="0"/
<MinVectorLength type="double" value="0"/
<XCenterMode type="int" value="0"/
<YCenterMode type="int" value="0"/</CObjBaseData
<CObjText
<Text type="CString"2222222</Text
<FontName type="CString"1LS-Arial</FontName

And than about 100 - 120 lines for each file.
So there seems nothing wrong with the text.

My goal is to replace the text 1LS-Arial or 1LS-Arial-U in 1LS-OCR-B-10
BT in each file but in some files the text 1LS-OCR-B-10 BT is already
present so needs no modification.

Pieros.





  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file


NickHK I'm sorry but when I use this code

Option Explicit

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

Sub read_file()

Dim InFile As Long
Dim OutFile As Long

InFile = FreeFile
Open "U:\Programs - Documents\MSExcel\Test zoek en vervang 4 -
aangepast volgens
forum\Approved\Cop00004500\00004583_001_KART_KM9_V 1.xml" For Input As
#InFile

OutFile = FreeFile
Open "U:\Programs - Documents\MSExcel\Test zoek en vervang 4 -
aangepast volgens
forum\Corrected\Cop00004500\00004583_001_KART_KM9_ V1.xml" For Output As
#OutFile

Print #OutFile, Replace(Input(LOF(InFile), #InFile), "1LS-Arial",
"1LS-OCR-B-10 BT")

Close #InFile
Close #OutFile

End Sub

I get the Run-time Error 62 again. (Input past end of file)
My text replacement wish is not a simple one I believe.

Pieros

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default The Print # command print not all rows from excel sheet to file

If you get that error, then you have text files with Unicode encoding. As
such, this code will not work.

You can adapt this :
http://support.microsoft.com/kb/193540

Or maybe use the FSO:
http://www.aivosto.com/visdev/fso.html

However, as your file are XML, you can open them directly in XL2002.
However, with your file, I get an error, as the first line "<?xml
version="1.0"?" is invalid.
Not sure how Excel would handle the encoding either.

NickHK

"pieros" wrote in message
oups.com...

NickHK I'm sorry but when I use this code

Option Explicit

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

Sub read_file()

Dim InFile As Long
Dim OutFile As Long

InFile = FreeFile
Open "U:\Programs - Documents\MSExcel\Test zoek en vervang 4 -
aangepast volgens
forum\Approved\Cop00004500\00004583_001_KART_KM9_V 1.xml" For Input As
#InFile

OutFile = FreeFile
Open "U:\Programs - Documents\MSExcel\Test zoek en vervang 4 -
aangepast volgens
forum\Corrected\Cop00004500\00004583_001_KART_KM9_ V1.xml" For Output As
#OutFile

Print #OutFile, Replace(Input(LOF(InFile), #InFile), "1LS-Arial",
"1LS-OCR-B-10 BT")

Close #InFile
Close #OutFile

End Sub

I get the Run-time Error 62 again. (Input past end of file)
My text replacement wish is not a simple one I believe.

Pieros



  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default The Print # command print not all rows from excel sheet to file

Anyway, thanks NickHK for your help sofar. I will try what you suggest
and hope it will work.

Thanks again,
Pieros.


NickHK wrote:
If you get that error, then you have text files with Unicode encoding. As
such, this code will not work.

You can adapt this :
http://support.microsoft.com/kb/193540

Or maybe use the FSO:
http://www.aivosto.com/visdev/fso.html

However, as your file are XML, you can open them directly in XL2002.
However, with your file, I get an error, as the first line "<?xml
version="1.0"?" is invalid.
Not sure how Excel would handle the encoding either.

NickHK





  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default The Print # command print not all rows from excel sheet to file

I don't use XML much, but it seems that your files are encoded but the XML
declaration does not include the encoding used. Hence Excel fails because it
assumes UTF-8, which is wrong.
Maybe one of these will help
http://msdn.microsoft.com/msdnmag/issues/01/05/xml/
http://www.w3.org/TR/2004/REC-xml-20.../#sec-guessing

VBA can still work with these files, but you have to allow for the
differences between these and normal ANSI files, which was assumed for the
code before.

You can send me a sample of the XML file if you want and I can see what you
have.


But I recommend you read up on encoding, XML and how Excel deals with both
of those, as I do not know much : ) .

NickHK

"pieros" wrote in message
ups.com...
Anyway, thanks NickHK for your help sofar. I will try what you suggest
and hope it will work.

Thanks again,
Pieros.


NickHK wrote:
If you get that error, then you have text files with Unicode encoding.

As
such, this code will not work.

You can adapt this :
http://support.microsoft.com/kb/193540

Or maybe use the FSO:
http://www.aivosto.com/visdev/fso.html

However, as your file are XML, you can open them directly in XL2002.
However, with your file, I get an error, as the first line "<?xml
version="1.0"?" is invalid.
Not sure how Excel would handle the encoding either.

NickHK





  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default The Print # command print not all rows from excel sheet to file

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


  #18   Report Post  
Posted to microsoft.public.excel.programming
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.

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
command line options/switches to print excel file Stranger[_2_] Excel Worksheet Functions 2 March 18th 09 06:36 AM
command line options/switches to print excel file Stranger[_2_] Excel Discussion (Misc queries) 1 March 17th 09 01:04 PM
how to print a sheet by command ghost Excel Discussion (Misc queries) 4 May 1st 07 05:33 PM
How to format the extension less file to print with Dos's Print Command Badshah Excel Discussion (Misc queries) 0 November 28th 06 12:44 PM
Create command button to print multiple worksheets in a excel file MarcoR Excel Discussion (Misc queries) 3 June 26th 06 07:07 PM


All times are GMT +1. The time now is 11:54 PM.

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

About Us

"It's about Microsoft Excel"