+ Reply to Thread
Results 1 to 28 of 28

Importing from a text file without opening

  1. #1
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Importing from a text file without opening

    Hi everyone.

    I am currently working in a lab that requires me to write up a spreadsheet that will basically import data from a text file (delimited by tabs) without actually having excel open it (because of legal issues we cannot see ALL results, we only want to pull the ones we want). Basically, I surfed the web and this forum and am having a hard time pulling all the information together to come up with a good macro. I want to link a macro to a command button. For example, for one test called "X", the samples will be labeled such as 22-X529458-Y295195-Z235011, in which Y and Z are also tests linked to that sample. Id like the macro to search through the text and find all the numbers associated with test X (in this case just 529458), and list them in a column. In the file there will also be a result for test X, and in the next column for that sample, I want the result to import in as well. Basically I only want the number, and then next to it the result that says "X/X; Mutation Absent"

    In the dummy file I uploaded it only has 1 sample, but there can be multiple, and with different tests like 87-X395190-Z235920, or 11-Y359383-Z359911, but will all be formatted with this nomenclature. Any help is VERY appreciated!! Thank you!!!
    Attached Files Attached Files
    Last edited by SupertechLC; 03-01-2011 at 04:13 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,336

    Re: Help with importing from a text file without actually opening it

    Hi SuperTechLC and welcome to the forum.

    See if these links help
    http://www.ozgrid.com/VBA/ExtractFromClosedWorkbook.htm

    If eyeballs are not allowed to view the textfile you might use the
    Application.ScreenUpdating = False command to keep people from seeing.
    The problem is that they might interrupt the VBA and see the file.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    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: Help with importing from a text file without actually opening it

    You can read the contents of the text file into memory and extract whatever information you need; it will not be opened in Excel.

    That said, I don't see at all how to extract the information you want based on the example file and the information you provided.
    Last edited by shg; 02-12-2011 at 01:26 PM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help with importing from a text file without actually opening it

    check attachment, save both files, open Excel file, press "Start", select saved .txt file.
    The data has been changed for testing purpose. That's all I understood from your explanation. If any changes are required. please shout.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Help with importing from a text file without actually opening it

    wow thank you for all the replies and help. I just got back from a work-filled weekend =( so ill take a look and post as soon as I can. Thank you all!

  6. #6
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Help with importing from a text file without actually opening it

    Wow that is exactly what I wanted... but what was changed in the text file?? No way to make that work with the file I gave??? The end result from those files is exactly what I need though.

  7. #7
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Help with importing from a text file without actually opening it

    To clarify, where it says P###### for a sample, the corresponding result would be the result after Factor II, F###### would be for Factor V, and the M###### for MTHFR (there are 2 results for these numbers).

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help with importing from a text file without actually opening it

    can you provide extensive explanation on:
    what we are looking for: as far as I understand, here 34-X892333-F352356 we are looking for 6 digits after X, right?
    what else we are looking for, what is the criteria?
    what result do we get from the your file attached?
    Last edited by watersev; 02-14-2011 at 11:10 AM.

  9. #9
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Help with importing from a text file without actually opening it

    Ok no problem, sorry I was not clear earlier. Yes the 6 digits after X are what Im after (of course If Im looking for test X). So my plan was to use the code on 3 different sheets... one looking for P######, one for F######, and one for M######. In this dummy sheet, the X###### was P###### when I submitted (I think) so it would be looking for the result after "Factor II 20210G>A G/G; Mutation Absent"

    If you look at the file imported into excel as a chart, itll line up like
    Factor II 20210G>A G/G; Mutation Absent

    And that would be the result for a P######.

    Out of the file, for the sheet I use to look for P######, I just want to pull from the text every 6 digit number after P, and the corresponding result.

    If it makes things easier I dont need the G/G, just the part that says Mutation Absent.

    So in the end I want

    892333 Mutation Absent
    next sample etc...

  10. #10
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help with importing from a text file without actually opening it

    see attachment, it searches for M, F, P tests in one go
    Attached Files Attached Files

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

    Re: Importing from a text file without opening

    or
    Please Login or Register  to view this content.



  12. #12
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    Hi guys, again im sorry for the late reply Ive just been swamped. I worked with the attachment, but i actually still have the problem of not being able to see just 1 of those results vs all three. Sorry I wasnt clear on that =( the point of not opening the text for me is so I dont actually see all the results, only what is needed. The code from snb is great for grabbing some of the numbers, but no results =(. Im going to try to explain what I need better.

    So I want a 5 sheet workbook. I already have written the first 2 pages, they are all just basically worksheets and have nothing to do with the samples, just instructions.

    The last 3 sheets are labeled Test P, Test F, Test M. Id like to make a button in each with a preformatted page, to take all corresponding test numbers and results and list them in 2 columns.

    So in sheet "Test P" id like a button, when pressed, prompts you to choose a text file, and then it imports all the P numbers and next to them the corresponding result. Again, the dummy file has 1 line (1 sample, multiple tests) but it can have many at once. They will be all set up the same way as the file looks except for the headers, so the results should be in the same place each time for each test ( a certain number of spaces after the label ex. Factor II ..........text in between....... Result)

    Hope this is a better description. Again thank you all for contributing and helping... this has been a real problem for me!

  13. #13
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    I just realized something that might help. If you scroll all the way to the right on the dummy file, each sample has a unique "<Header AccessionNumber="34-P892333-F352356" that is easier to use I would think for the number extraction. I modified the dummy file so it now has more samples on it and looks more like a file I would actually get.

    To reiterate:

    Test P = Factor II 20210G>A G/G; Mutation Absent
    Test F = Factor V 1691G>A G/G; Mutation Absent
    Test M = MTHFR 677C>T C/C; Mutation Absent 0.99751 MTHFR 1298A>C A/C; Heterozygous

    And I just need the "G/G; Mutation Absent" part for each test as a result. The Test M has 2 results. Id like those to list in 2 columns.

    So For example, the Test P Sheet will end up looking like

    Accession number || Result
    892333 || G/G; Mutation Absent
    823000 || G/G; Mutation Absent
    777829 || G/G; Mutation Absent


    So i dont want 1 button to do it all (unless it easier to program), I just need 1 set of code to handle test P, another for test F, and 1 for test M.

  14. #14
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    here is the dummy file.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    impossible?? =(

  16. #16
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,336

    Re: Importing from a text file without opening

    AWK - look it up!

  17. #17
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Importing from a text file without opening

    check attachment
    Attached Files Attached Files
    Last edited by watersev; 02-24-2011 at 05:32 AM. Reason: added code action if nothing is found

  18. #18
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    Wow thats amazing!! The only thing thats missing is the fact that it only picks up F-tests or M-tests if it is first in the name. In this case for the dummy, I need it to pick up all the F's, ex. like in 99-P777829-F111333-M662222, I need it to grab F111333. But thats really amazing thanks for all your help watersev!

  19. #19
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Importing from a text file without opening

    check attachment, I've made some corrections regarding your last post
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    By George I think we got it!! THANK YOU SO MUCH you have no idea how much this helps.... It saves me hours of sorting and legal paperwork haha. Thank you for staying with me on this it was a lot to ask and you really came through. Amazing job. Could not be more perfect.

  21. #21
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Importing from a text file without opening

    actually it could ... I know that ...if you are ok with the result and there are no outstanding issues here, please mark this thread as solved (for How To questions please refer to Forum rules)

  22. #22
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    oh crap i just realized that the M test has 2 results... looking at the code you got the 677C>T one, but there is also a 1298A>C one thats actually right after that. I am obviously not proficient in code like anyone on this forum and I apologize for my lack of skills. Im trying to figure out the your code here and where you tell it to place the text in the cells. I also want to move everything down and have it start "pasting" at row 6 cause I have headers in the page to make it look nice. So test P and F are perfect (pending I figure out how to move the text down) and test M just needs the other result. Im trying to look at your code to learn how, but I keep messing things up =(.

  23. #23
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Importing from a text file without opening

    it was my fault I just did not notice second result for M-test, check attachment, it should correct that to be as you'd like. In order to move result table for example: 5 rows down (columns are the same):
    Please Login or Register  to view this content.
    - the line responsible for output - as it now
    5 rows down:
    Please Login or Register  to view this content.
    - 5 rows down - left upper cell - [a5]
    I have moved result down to [a5] cell. Please test.
    Attached Files Attached Files

  24. #24
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    Im getting syntax error at

    Please Login or Register  to view this content.
    and it happens after I click the button for M test.

  25. #25
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    oh i think its just the space between sub and matches... i will try to fix

  26. #26
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    Ok i got it to work and it looks really great! I was able to move the output further down without a problem, except for some reason it deletes values (my headers) in row 1-5 (for Ptest and Ftest) and rows 1-4 for M test. But the results work perfectly!!

  27. #27
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    haha nevermind I got it... all I did was delete the
    Please Login or Register  to view this content.
    and now the file works so beautifully.

  28. #28
    Registered User
    Join Date
    02-11-2011
    Location
    new york, ny
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Importing from a text file without opening

    pending any other things I forget.. .this has been quite an experience! I greatly appreciate all your help watersev and will do my best to keep up on my excel-ing. Thank you!!

+ 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