1

Topic: I can not read a file htm as the text means VBA + I ask to check up pair of my functions.

Hello!
It is a little prehistory - I the doctor, I do a macro for parsing of the given ultrasonics and an insertion of measurements in the protocol since to rewrite manually long and not correctly.
The pregoing version worked on Apache OpenOffice 4 (itself wrote on OOBasic), now I work in other place - is license MS Office, therefore decided to alter and refine the old version (as the scanner another and all the same the old does not work).
To what wrote - I am not engaged in programming professionally, but to my city  who helps with access I can not find, therefore the part of questions will be for local old residents ridiculous.
Actually the subject - the scanner produces the data in a format htm, I by means of connected library MS HTML Object Library pull out the text, and actually I transfer a line in a parcer. But for some reason read a file htm at line I cannot.
Even if to open a notepad and to save as txt. And here if to create empty txt, to open a notepad htm to select and copy all in txt and to save, reads perfectly.
I read a line the following function:

Function GetText (sFile As String) As String
Dim nSourceFile As Integer
Dim sText As String
Close
nSourceFile = FreeFile
Open sFile For Input As #nSourceFile
sText = Input $ (LOF (1), 1)
Close
GetText = sText
End Function

In nesting both test files htm and txt received by a copying method in a notepad.

2

Re: I can not read a file htm as the text means VBA + I ask to check up pair of my functions.

The original file - two could not put at once.

3

Re: I can not read a file htm as the text means VBA + I ask to check up pair of my functions.

HTM - Unicode
TXT - ANSI

4

Re: I can not read a file htm as the text means VBA + I ask to check up pair of my functions.

Andrey A. Markine;
I hope at you 32 office
You take from here all code, you save it in the general unit.
And function such

Function GetText (sFile As String) As String
Dim TristateState as Boolean
Dim oFSO as object, oTXT as object
TristateState = IsUTF16TXT (sFile)
Set oFSO = CreateObject ("Scripting. FileSystemObject")
Set oTXT = oFSO.OpenTextFile (sFile, 1, TristateState)
GetText = oTXT.ReadLine
oTXT.Close
set oTXT = nothing
set oFSO = nothing
End Function

5

Re: I can not read a file htm as the text means VBA + I ask to check up pair of my functions.

fix

UTF-16, wrote:

Andrey A. Markine;
I hope at you 32 office
You take from here all code, you save it in the general unit.
And function such

Function GetText (sFile As String) As String
Dim TristateState as Boolean
Dim oFSO as object, oTXT as object
TristateState = IsUTF16TXT (sFile)
Set oFSO = CreateObject ("Scripting. FileSystemObject")
Set oTXT = oFSO.OpenTextFile (sFile, 1, TristateState)
==> GetText = oTXT.ReadAll
oTXT.Close
set oTXT = nothing
set oFSO = nothing
End Function

6

Re: I can not read a file htm as the text means VBA + I ask to check up pair of my functions.

Akina;
Thanks - prompted that a problem with codings.
Now all works, simply the coding I transfer in shape:

Function GetText (sFile As String, sCharset As String) As String
Dim oADODBStream As ADODB.Stream
Set oADODBStream = New ADODB.Stream
oADODBStream. Charset = sCharset
oADODBStream. Type = adTypeText
oADODBStream. Open
oADODBStream. LoadFromFile (sFile)
GetText = oADODBStream. ReadText
oADODBStream. Close
Set oADODBStream = Nothing
End Function