+ Reply to Thread
Results 1 to 12 of 12

Txt import

  1. #1
    Registered User
    Join Date
    12-22-2010
    Location
    Slovakia
    MS-Off Ver
    Excel 2010
    Posts
    20

    Txt import

    Hi,

    I guess i didnt google enough, but can you guys help to build a simple code, which would import txt file into excel..? iIl fix the separator later, all i need in excel is, to get the browser open
    (or event hard coded address),and to choose the file to import. Somehow i cant figure it out. Thank you.

    IB
    Last edited by admssm; 12-30-2010 at 09:43 AM.

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

    Re: Txt import into excel issue

    Hi admssm,

    I use the following code to import files:
    Please Login or Register  to view this content.
    All the real work is rolled into the Application.FindFile command.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Txt import into excel issue

    Hi,

    How about

    Please Login or Register  to view this content.
    Rgds
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    12-22-2010
    Location
    Slovakia
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Txt import into excel issue

    Thank you for your help. How can i "tell" the macro that i want to set this parameter ":" to separate the data automatically..? Once i run the command, i have to go thru the import process manually.. can this be automated via chain of commands as well..?

    Thx

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

    Re: Txt import into excel issue

    Look at:
    http://www.cpearson.com/Excel/ImpText.aspx

    I don't know if there is an easier way.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Txt import into excel issue

    Hi,

    If you use the macro recorder to open your text file, delimiting it as necessary during this process, you'll find that you end up with code like the following.

    Please Login or Register  to view this content.
    Just include this array variable syntax after the code I gave you earlier in the workbooks.open ....coding.

    Rgds



    Regards

  7. #7
    Registered User
    Join Date
    12-22-2010
    Location
    Slovakia
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Txt import

    Thank you for your help.
    Once i import the txt, it opens a new sheet. How can i set the macro to put the file into the same sheet im running the macro from..?

    Thx

  8. #8
    Registered User
    Join Date
    12-22-2010
    Location
    Slovakia
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Txt import

    Im attaching excel, which im using to import the macros. Each sheet contains different macro-button. Once i set the separators manually, the file opens in a new excel. How do i "tell" the file to open in the same window im running the macro form..?
    Thx
    Attached Files Attached Files
    Last edited by admssm; 12-30-2010 at 07:27 AM.

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

    Re: Txt import

    Hi admssm,

    When you run your "Get Data" macro it opens a whole new workbook, not just another sheet. You will need to flip back and forth between the two workbooks to copy and paste data. The code goes like this

    You need the name of the new, just opened workbook and your current old workbook so I do this first.

    Please Login or Register  to view this content.
    If you need more data from the newly opened worksheet you get back to it using with code of
    Please Login or Register  to view this content.
    When you are done with the newly opened workbook you can close it with the code
    Please Login or Register  to view this content.
    Writing code to automate the whole process is a little hard, as you are discovering. The data that is coming in needs to be arranged in a consistant place. If it is longer or shorter you may need to write code that varies and deals that too.

    I hope this helps you get through your import problem.

  10. #10
    Registered User
    Join Date
    12-22-2010
    Location
    Slovakia
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Txt import

    Hi Marvin,

    thank you for your help.. i figured it out eventually.. :

    How can i set the separators.. for example "," ":"

    I saw the some example on the net, but since im not very skilled *(blessed) with macro, i couldnt understand the syntax.. if you will be kind enough to put small example of the marco separator.
    thx
    Last edited by admssm; 12-30-2010 at 09:26 AM.

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

    Re: Txt import

    Hi,

    The macro sample above is in your opened Excel Workbook. I think you want to import data from a text file into this opened workbook. That is the name of the thread and I thought was your need.

    Macro code is not copied from the opened text file into the current workbook.

    It is hard for us to guage your experience with programming and ability to read and understand VBA. We also have a term problem between Data and Macro.

    After looking at your example file, it looks like you have a Linux Server that is sending you text files and you want to add some of this data to your Excel spreadsheet. I am concerned that I find you have code that is trying to send out email, automatically. (I hate spam). I'm not sure I understand your problem well enough to help.

  12. #12
    Registered User
    Join Date
    12-22-2010
    Location
    Slovakia
    MS-Off Ver
    Excel 2010
    Posts
    20

    RESOLVED: Txt import

    Fair enough.. I understand your concerns. After all, you helped me at least to automated the import, which i appreciate. Thank you for your help.

    IB

+ 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