Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   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.





  #2   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

  #3   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



  #4   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



  #5   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







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 01:40 AM.

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"