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
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
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.
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.
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.
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.
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?
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?
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?
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 V, T$(), R&, S$() V = ThisWorkbook.Path & "\Data .dat" If Dir(V) = "" Then Beep: Exit Sub Open V For Binary As #9 V = Split(Input(LOF(9), #9), "Z " & Chr(2)) Close #9 [A1].Value = Split(V(0))(0) ReDim T(1 To UBound(V), 1) For R = 1 To UBound(V) S = 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(R, 0) = S(0) T(R, 1) = 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 …
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.
Bookmarks