trpkob
07-05-2012, 07:26 AM
I have a binary file with hexadecimal information stored within it at hexadecimal addresses. I would like to read in the contents of the file into Excel at specific addresses. For instance, if at 0x0000 there was 00, I would want to read that in and at other specific address. So far I have only been able to read in the entire file. Also, if ASCII information is readable I would want that to be read in instead of the binary. I would need to read in at certain addresses for a certain length. For example, at 0x204 I would want to read for a hex length of 4 generating E2 C1 EC F9 and at 0x208 I would also want to read a hex length of 4 generating 02 00 00 00. I want to store the contents and address in a separate cell. So column A would have the address and column B would have the contents. I have attached a screenshot of the file highlighting these areas. The code below is for reading the entire file which takes forever and sometimes freezes Excel; I only want to read in the data at certain addresses. Any suggestions on VBA code that could accomplish this?
Sub Button1_Click()
Dim intFileNum%, bytTemp As Byte, intCellRow
intFileNum = FreeFile
intCellRow = 0
Open "C:\Documents and Settings\...." 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
Sub Button1_Click()
Dim intFileNum%, bytTemp As Byte, intCellRow
intFileNum = FreeFile
intCellRow = 0
Open "C:\Documents and Settings\...." 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