+ Reply to Thread
Results 1 to 27 of 27

macro import file hex in excel

  1. #1
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    macro import file hex in excel

    cerco una macro che mi permetta di importare un file hex in excel.
    tanks

    I want a macro that allows me to import a hex file into Excel.
    tanks
    Last edited by tatop; 01-19-2012 at 07:09 PM. Reason: error only italian

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: macro import file hex in excel

    a hex file? what is that. is it a text file with hex numbers?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by martindwilson View Post
    a hex file? what is that. is it a text file with hex numbers?
    I have to import the files with a programmer to read eeprom ... having an extension. bin and contain the hex.
    tanks

  4. #4
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: macro import file hex in excel

    If you have a bin(ary) file, then don't you want to open it in a hex editor to review/make changes? Apologies, i just can't see why you might open it in Excel...

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: macro import file hex in excel

    Not too complicated; reading as HEX file, converting to ascii

    Please Login or Register  to view this content.



  6. #6
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by snb View Post
    Not too complicated; reading as HEX file, converting to ascii

    Please Login or Register  to view this content.
    TANKS for macro but I try a macro that displays the values ​​of excel a BIN file in hex, sorted as if it were an editor and divided by single byte.
    Attached Images Attached Images

  7. #7
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by Firefly2012 View Post
    If you have a bin(ary) file, then don't you want to open it in a hex editor to review/make changes? Apologies, i just can't see why you might open it in Excel...
    I would like to open it in Excel because I have to perform calculations using the algorithm on the file and then save it in. bin, to rewrite the EEPROM

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: macro import file hex in excel

    i still don't understand, what would an example excel file look like?

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: macro import file hex in excel

    Yes I see, but are you aware that a cell in Excel can only show a limited amount of characters ?
    So where do you want the hex characters to be shown in Excel ??

  10. #10
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by martindwilson View Post
    i still don't understand, what would an example excel file look like?
    0 1 2 3 4 5 6 7 8 9 a b c d e f
    0 af 12 bf ff 44 5f 6f ff ff 12 f1 34 55 89 ff ac
    10 5f 6f ff ff 12 ff 44 5f 6f ff 5f 6f ff ff 12 12
    20 f1 34 f1 34 55 89 ff ac ff 44 5f 6f ff ff 12 12
    30 6f f1 34 55 89 f1 34 55 89 ff ac ff 44 5f 6f ff
    40 5f 6f ff ff 12 5f 6f ff ff 12 ff 44 5f 6f ff ff
    50 bf ff 44 5f 6f ff ff 12 f1 34 55 89 ff ac ff ff
    60 f1 34 55 89 5f 6f ff ff 12 12 f1 34 55 89 ff ac
    70 f1 34 55 89 5f 6f ff ff 12 12 f1 34 55 89 ff ac
    80 f1 34 55 89 ff ac ff 44 5f 6f ff ff 12 ff 44 5f
    90 ff 44 5f 6f ff bf ff 44 5f 55 89 ff ac ff 44 5f
    100 f1 34 bf ff 44 5f 6f ff ff 12 f1 34 55 89 ff ac
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by snb View Post
    Yes I see, but are you aware that a cell in Excel can only show a limited amount of characters ?
    So where do you want the hex characters to be shown in Excel ??
    ok, every single cell in excel it must contain two characters (a single bite (AB) ok ?????
    see attached sample file first

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: macro import file hex in excel

    You only have to change the file's name

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    thanks for the macro, but I have two problems:
    1) the last cell of the first line is empty and the value of that cell is inserted into the cell below, so moving 'the last column at the bottom of a cell;
    2) values ​​in individual cells are displayed as text but I would display them as hexadecimal values ​​as I have to make calculations.
    You can edit the macro please
    thanks a lot
    Attached Files Attached Files

  14. #14
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: macro import file hex in excel

    Try this one:
    Please Login or Register  to view this content.
    Ben Van Johnson

  15. #15
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    tanks but when play macro :

    index out of range

  16. #16
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: macro import file hex in excel

    When I was writing/testing the macro, I used a file from my own computer and entered the output to a worksheet I named BEN. The mod below will write the output to what ever the active sheet is. But you must still tell the macro where the binary file is located >> change the BLUE portion of the code below.
    Please Login or Register  to view this content.
    1. What is the path and name of your file ?
    2. Where did you copy the code (did you put it in a worksheet module)?

  17. #17
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by protonLeah View Post
    When I was writing/testing the macro, I used a file from my own computer and entered the output to a worksheet I named BEN. The mod below will write the output to what ever the active sheet is. But you must still tell the macro where the binary file is located >> change the BLUE portion of the code below.
    Please Login or Register  to view this content.
    1. What is the path and name of your file ?
    2. Where did you copy the code (did you put it in a worksheet module)?
    TANKS, works perfectly ....... but I still need you !!!!!!
    I'm sorry .... Once I changed the file in excel how do I save it in. BIN?? I need to calculate a few bytes to join 4-cell, and I do it with the following function: "= A1&A2&A3&A4 "..... but then how do I rewrite the result obtained on 4 separate cells?hopefully last question: can you give me create a macro that I want to ask me to upload files without having to change each time the macro??
    tanks
    tanks

  18. #18
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: macro import file hex in excel

    Does the EEPROM use Big- or Little-endian data? That may well determine how you want the data extracted and written to the file.

  19. #19
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by tatop View Post
    TANKS, works perfectly ....... but I still need you !!!!!!
    I'm sorry .... Once I changed the file in excel how do I save it in. BIN?? I need to calculate a few bytes to join 4-cell, and I do it with the following function: "= A1&A2&A3&A4 "..... but then how do I rewrite the result obtained on 4 separate cells?hopefully last question: can you give me create a macro that I want to ask me to upload files without having to change each time the macro??
    tanks
    tanks
    UP !!!!!! tankssss

  20. #20
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    works perfectly ....... but I still need you !!!!!!
    I'm sorry .... Once I changed the file in excel how do I save it in. BIN?? the edited file copy it
    in a new folder and from there I would save as. bin by entering the name.
    You can become part of that macro please??
    I've lost all night but nothing. thanks
    I added your macro to open files with this code:
    Sub BinToHex()
    Dim ColumnNumber As Long, _
    RowNumber As Long, _
    Ndx As Long, _
    InBucket As Variant

    Dim FileName As String



    FileName = Application.GetOpenFilename

    If Not FileName = "False" Then MsgBox FileName

    Open FileName For Binary As #1
    InBucket = Input(LOF(1), #1)
    Close #1
    RowNumber = 3
    ColumnNumber = 1

    For Ndx = 1 To Len(InBucket)
    ColumnNumber = ColumnNumber + 1
    Cells(RowNumber, ColumnNumber) = Hex(Asc(Mid(InBucket, Ndx, 1)))
    If (Ndx Mod 16) = 0 Then
    RowNumber = RowNumber + 1
    ColumnNumber = 1
    End If
    Next Ndx
    Call SOSTITUISCI_00
    Call FILE_BIN_ORIGINALE
    End Sub


    Private Sub CommandButton1_Click()

    End Sub





    and it works fine.

    aspect of your news

  21. #21
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: macro import file hex in excel

    Please take a few minutes to read the forum rules, and then edit your post to add CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  22. #22
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: macro import file hex in excel

    tatop seems to be done but I thought I would post the update anyway:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by protonLeah View Post
    tatop seems to be done but I thought I would post the update anyway:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    tanks , the first macro is OK...loaf file OK
    but the macro SaveAsBinary dont go!!!
    show this error:
    error of runtime "438"
    Property or method not supported

    can u correct , please

    thank again !!!!!!

  24. #24
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    up ! ! ! ! !

  25. #25
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: macro import file hex in excel

    Sorry, the save macro runs on my machine. I'm not familiar with runtime error 438. Can you step through the "save" macro to see which line is highlighted when it stops?

  26. #26
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    error 438.jpg

    error of runtime "438"
    Property or method not supported

  27. #27
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Attachment 137838

    error of runtime "438"
    Property or method not supported

  28. #28
    Registered User
    Join Date
    01-19-2012
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: macro import file hex in excel

    Quote Originally Posted by protonLeah View Post
    Sorry, the save macro runs on my machine. I'm not familiar with runtime error 438. Can you step through the "save" macro to see which line is highlighted when it stops?

    I'm sorry, the macro in Excel 2007 works, the problem was that I was using Excel 2003. I have it converted and it works .... only problem is that, hex conversion is incorrect, because when I save the bin file I see only data wrong.
    my new code is:

    Please Login or Register  to view this content.
    Attached Images Attached Images

  29. #29
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: macro import file hex in excel

    O.k. the error 438 is because you don't seem to have the Analysis ToolPak installed on your machine:

    HEX2DEC

    If this function is not available, and returns the #NAME? error, install and load the Analysis ToolPak add-in.

    On the Tools menu, click Add-Ins.
    In the Add-Ins available list, select the Analysis ToolPak box, and then click OK.
    If necessary, follow the instructions in the setup program.
    2. In the line:

    Please Login or Register  to view this content.
    you are trying to use the CLng function to convert a value on the worksheet to a long integer. However, you have made a couple of mistakes.

    The Clng function works with decimal values such as 1202.667 converting it to 1203. In your spreadsheet you have strings representing hex numbers such as "FE" in a cell, say D4.

    Since F & E are not decimal digits, were you to write the function correctly you would write Clng(Range("D4").Value) or Clng(Cells(RowNdx,ColNdx).Value) you would get an error.

    But, you wrote the Clng function wrong, so it returns an error value to the Chr() function and it in turn errors since there is no character mapped to those error values.
    The result is that the line simply loads the output array with error values.
    -------------------------
    Also, the lines:
    t0 = Timer, and
    Debug.Print "elapsed time ", Timer - t0 should be deleted, that was just an experiment for me while making changes.
    Last edited by protonLeah; 01-25-2012 at 12:09 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1