tags:

views:

910

answers:

2

I have a binary file that resulted from a program written in Compaq Visual Fortran. How can I read specific lines and save them in an Excel sheet?

+3  A: 

You have to open it using "Binary Access".

See http://www.vbforums.com/showthread.php?t=430424

Sub Temp()
    Dim intFileNum%, bytTemp As Byte, intCellRow%
    intFileNum = FreeFile
    intCellRow = 0
    Open "C:\temp.bin" For Binary Access Read As intFileNum
    Do While Not EOF(intFileNum)
        intCellRow = intCellRow + 1
        Get intFileNum, , bytTemp
        Cells(intCellRow, 1) = bytTemp
    Loop
    Close intFileNum
End Sub
Curtis Inderwiesche
A: 

Another way is using ADODB.Stream:

With CreateObject("ADODB.Stream")
    .Open
    .Type = 1  ' adTypeBinary
    .LoadFromFile file.Path
    bytes = .Read
    .Close
End With

(Sorry, I'm not actually sure what library it's in, which is why this sample code uses CreateObject and the literal value 1 instead of the named constant adTypeBinary!)

Todd Owen