+ Reply to Thread
Results 1 to 23 of 23

Reading Complex Binary Files into a worksheet

  1. #1
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Reading Complex Binary Files into a worksheet

    Hey everyone,

    I hope you can assist me with something. I'm trying to read binary files into an excel worksheet using vba. Below is an example of one of the lines in the file. There are at least 1000 lines in this file. Does anyone have a method they've used to beat something like this?

    0311stat2017  °ü  /+jX0jX0jX VISA 71050 ICL REGZ 209925 ¡   b n

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Reading Complex Binary Files into a worksheet

    Hello anthony1312002,

    Were you hoping Excel could "translate" the binary file for you?

    What type of result do want after importing the binary file?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    Hey Ross, I'm so sorry for not getting back to you sooner. I'm trying to see if I can make the file readable so that the following happens in excel after import:


    0311stat2017  °ü  /+jX0jX0jX VISA 71050 ICL REGZ 209925 ¡   b n

    Becomes:

    0311 stat2017 VISA 71050 ICL REGZ 209925

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Reading Complex Binary Files into a worksheet

    Hello Anthony,

    This is quite a complex operation due to the rules needed to make the output readable. Here is a User Defined Function that will pull out only the following characters: space, 0 to 9, minus sign, A to Z, underscore, and a to z. The result of this macro on the string you provided is 0311stat2017 jX0jX0jX VISA 71050 ICL REGZ 209925 b n. It is much better but not perfect.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    Thank you so much for helping me with this. Question, how can access the directory and the file and then apply this function?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Reading Complex Binary Files into a worksheet

    Hello Anthony,

    Are all the binary files in the same directory?

    Can the directory's path be added into the code?

    If so what is the directory's path?

    What extension do these files have?

    Will each file's contents be placed into a single cell on the worksheet?

    Is there a break like a blank row between each file?

  7. #7
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    Hey Leith, yes, they are in the same directory. The path is C:\Users\APhillips\Documents\OPEX150\STAT2018.1

    STAT2018.1 is the name of the file.

  8. #8
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    But I would like to be able to navigate to a directory in case the path ever changes.

  9. #9
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    Hi Leith,

    I hope in my earlier post I wasn't confusing. If you can still help it would really be great.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Reading Complex Binary Files into a worksheet

    If you know the structure (data types of the fields) of the file you might be able to read the binary file directly and output to worksheet.

    Are you able to post example binary file with expected output? A few records should be enough.
    Cheers
    Andy
    www.andypope.info

  11. #11
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    How do I attach a file?

  12. #12
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    Unfortunately I'm unable to attach a file due to security policies. But here is a fuller representation of the file I'm dealing with.

    Please Login or Register  to view this content.
    The output would be something like you listed earlier

    0311 stat2017 VISA 71050 ICL REGZ 209925
    Last edited by anthony1312002; 06-01-2018 at 10:08 AM.

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Reading Complex Binary Files into a worksheet

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  14. #14
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    Hey Andy, I just updated my post.

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Reading Complex Binary Files into a worksheet

    When you post it like that it become just text.

    Where does the original file come from?
    Ideally you would need to know what type of information is contained in each record of the file. Something like, 1st field if text, 2nd field is a Integer etc.

    If you don't know that then the only thing you can do is remove characters not in the normal 32 to 127 range, which is what Leith's code is doing.

  16. #16
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    I see. Okay, that is part of my challenge. I don't have access to the actual structure that this file is created from. I only receive it. I guess my only option is to do as you stated and use Leith's code. But even with that I'm not sure how to setup the code so that I can navigate to the file to run the code on it.

  17. #17
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    Hmm, that's a challenge I'm facing. I don't have access to the structure that creates the file I receive. I guess as you said my only option would be to use Leith's code. But I'm not able to adapt it so that I can navigate to the file and run it. How can I achieve this?

    Please Login or Register  to view this content.

  18. #18
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Reading Complex Binary Files into a worksheet


    Hi !

    Retry to attach the source file 'cause it would be easier for us, as nothing complex to read any file …

  19. #19
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Reading Complex Binary Files into a worksheet

    Hi Marc,

    I can't attach a file due the security policies placed on our machines here. But I think we might have a work around. What if you copy the text below into a text file and then save it as a binary file? Would that work in giving you a file that could be tested?


    Please Login or Register  to view this content.

  20. #20
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Reading Complex Binary Files into a worksheet

    Use creating binary files will not be of much use.

    First I think you need help from the supplier of the files in the form of them providing details or alternatives.
    Where do the files come from? Have you asked whether they can be provided in a different format?

  21. #21
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Reading Complex Binary Files into a worksheet


    anthony, according to your last "attachment", what are the first two records expected in a worksheet and within which columns ?

  22. #22
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool As a starter …


    As I may not have any time next week until Thursday, according to your last "attachment",
    as the initial "explanation" does not match with this attachment,
    as the very poor explanation on Excel side, this is a demo extracting raw data to two columns
    like any text file (can't waste time to find any binary logic without required crystal clear informations)
    in order you get a code base you can mod to suit your real need as we can't guess,
    update the initial path & name of source data file (if you want to navigate to a directory to choose a file,
    a must read in VBA inner help : GetOpenFilename method !) :

    PHP Code: 
    Sub Demo1()
        
    Dim VT$(), R&, S$()
            
    ThisWorkbook.Path "\Data .dat"
            
    If Dir(V) = "" Then Beep: Exit Sub
            Open V 
    For Binary As #9
            
    Split(Input(LOF(9), #9), "Z " & Chr(2))
            
    Close #9
            
    [A1].Value Split(V(0))(0)
            
    ReDim T(1 To UBound(V), 1)
        For 
    1 To UBound(V)
                
    Split(V(R), " " Chr(14))
            If 
    UBound(S) < 2 Then
                S
    (1) = Right(S(0), 7)
                
    S(0) = Left(S(0), InStrRev(S(0), " ") - 1)
            
    End If
                
    T(R0) = S(0)
                
    T(R1) = S(1)
        
    Next
            
    [C1:D1].Resize(UBound(T)).Value T
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 06-03-2018 at 06:32 PM. Reason: optimization …

  23. #23
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: As a starter …

    Hey everyone, I do apologize for being unclear. This has really been a frustrating project for me as I've not been given the needed information that I could pass on to you so that you could help me. I'm going to table this for a while until they can provide me with more detail. But thank you all so much for you willingness to help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Pivot tables reading binary data
    By hsouth11 in forum Excel General
    Replies: 10
    Last Post: 05-12-2018, 12:05 AM
  2. Reading random binary file with header
    By Moadll in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2016, 10:46 AM
  3. [SOLVED] Need help converting Hex to Long / Reading file contents at binary level
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-04-2015, 07:51 PM
  4. Excel Binary Files and Mac Mail
    By hambly in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 01-14-2015, 06:17 PM
  5. Problem using Name As to move files after reading CSV Data into a WorkSheet
    By mcdirt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-06-2013, 09:34 AM
  6. Reading a binary file
    By Andrew-R in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-13-2012, 10:16 AM
  7. Reading binary file
    By Maxi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-14-2006, 07:20 PM

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