Ich habe eine Binärdatei, die von einem Programm in Compaq Visual Fortran geschrieben wurde. Wie kann ich bestimmte Zeilen lesen und in einer Excel-Tabelle speichern?Wie kann ich eine Binärdatei mit VBA lesen?
4
A
Antwort
4
Sie müssen es mit "Binary Access" öffnen.
Siehe 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
5
Ein anderer Weg ADODB.Stream verwendet:
With CreateObject("ADODB.Stream")
.Open
.Type = 1 ' adTypeBinary
.LoadFromFile file.Path
bytes = .Read
.Close
End With
(Sorry, ich bin nicht wirklich sicher, welche Bibliothek es ist in, weshalb dieses Codebeispiel verwendet Create und der Literalwert 1 anstelle der benannten Konstante adTypeBinary!)
+0
Die Bibliothek ist Microsoft Active Data Object. –
Wie hat eine Binärdatei "Zeilen"? –