How to read data from binary file?

V

Valery

Hello Guys!
Such a question to you

I have a binary file. I need to get from this file data in 100 byte to cell
and after I need to create a new binary empty file and unload it received
data from the first binary file.

Thanks for you time.
Regards Valery.
 
J

Joel

You don't have to put any data into a worksheet. You can open two files and
move data from one file to the second file

Sub fixevents()
Const ForReading = 1, ForWriting = 2, _
ForAppending = 3

Set fs = CreateObject("Scripting.FileSystemObject")



fileToOpen = Application _
.GetOpenFilename("Binary Files (*.bin), *.bin", _
Title:="Read File")
If fileToOpen = False Then
MsgBox ("Cannot Open File - Exiting Sub")
End If

Set fin = fs.OpenTextFile(fileToOpen, _
ForReading, TristateFalse)

fileToOpen = Application _
.GetOpenFilename("Binary Files (*.bin), *.bin", _
Title:="Write File")
If fileToOpen = False Then
MsgBox ("Cannot Open File - Exiting Sub")
End If


Set fout = fs.CreateTextFile _
(fileToOpen, True)



Do While fin.AtEndOfStream <> True
readdata = fin.Read(Characters)
fin.write readdata

Loop
fin.Close
fout.Close
End Sub
 
V

Valery

Joel Thanks !
Help me please one more
I need the open file without dialog box
it's possible ?
in second i would read data from binary file , put in cell 100 byte in some
cell on the sheet And after unload 100 to a new binary file from cell

Thanks for you time.
 
J

Joel

from

Set fout = fs.CreateTextFile _
(fileToOpen, True)

Set fin = fs.OpenTextFile(fileToOpen, _
ForReading, TristateFalse)

to

fileToOpen = "c:\temp\book1.xls"
Set fout = fs.CreateTextFile _
(fileToOpen, True)

fileToOpen = "c:\temp\book2.xls"
Set fin = fs.OpenTextFile(fileToOpen, _
ForReading, TristateFalse)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top