read a binary file in VBA

how can I read a binary file using VBA

You have to open it using “Binary Access”.

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

Sub Temp()     Dim intFileNum%, bytTemp AsByte, intCellRow%     intFileNum = FreeFile     intCellRow =0     Open "C:\temp.bin"For Binary Access Read As intFileNum     DoWhileNot EOF(intFileNum)         intCellRow = intCellRow +1         Get intFileNum,, bytTemp         Cells(intCellRow,1)= bytTemp     Loop     Close intFileNum EndSub

Another way is using ADODB.Stream:

With CreateObject("ADODB.Stream")
    .Open
    .Type =1  ' adTypeBinary
    .LoadFromFile file.Path
    bytes =.Read
    .Close
EndWith
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s