Consulting

Results 1 to 7 of 7

Thread: Importing a Text File

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Importing a Text File

    I am using this code to ask the user which text file to open:

    [VBA]If Not Application.Dialogs(xlDialogImportTextFile).Show Then[/VBA]

    the name and the place will always be different but the column widths will always be the same. I want to change that code to always have the same column widths. The only line I need to set is 49. Also is it possible it to be coded that after the user choses which text file to import, it doesn't show the text file import dialog at all?

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    The easiest way to get the code to do what you want would be to record a macro when you do it manually.

    That can then be altered to incorporate user input, for which I would recommend GetOpenFilename.

    PS What does this mean?
    Quote Originally Posted by Djblois
    The only line I need to set is 49.

  3. #3
    Djblois.
    I had a similar problem by the looks of it. It was solved here.

    http://www.ozgrid.com/forum/showthread.php?t=32244

    I hope you don't find it unethical showing answers from the "competitor's" site

    If you need the whole code as I currently have it, and it works good, let me know please.

    HTH

    John

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Quote Originally Posted by jolivanes
    Djblois.
    I had a similar problem by the looks of it. It was solved here.

    http://www.ozgrid.com/forum/showthread.php?t=32244

    I hope you don't find it unethical showing answers from the "competitor's" site

    If you need the whole code as I currently have it, and it works good, let me know please.

    HTH

    John
    Take a look at this. Solution provided by VBAX site with full coding sample .

    http://vbaexpress.com/forum/showpost...69&postcount=6

    Charlize

  5. #5
    Hi Charlize.
    Works good but I assume it depends on Djblois' textfile structure. I tried your workbook with the textfile mentioned in the ozgrid post and that doesn't work. Have not looked at the macro though. The saying that there are many roads leading to Rome is true. In your case that should be Brussel or Antwerpen.
    Have a good day and thanks.
    John

  6. #6
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Quote Originally Posted by jolivanes
    Hi Charlize.
    Works good but I assume it depends on Djblois' textfile structure. I tried your workbook with the textfile mentioned in the ozgrid post and that doesn't work. Have not looked at the macro though. The saying that there are many roads leading to Rome is true. In your case that should be Brussel or Antwerpen.
    Have a good day and thanks.
    John
    The version I provided is based upon following conditions :
    - 5 numbers on a line separated with a space
    1 2 3 4 5
    6 7 8 9 10
    - last line of file is empty
    The OP wanted to import like this :
    1 6
    2 7
    3 8
    4 9
    5 10
    And you can select the file that needs to be imported.

    Charlize

    ps.: I prefer Heverlee (Leuven) instead of Brussel or Antwerpen. By the way, will take a look at your pdf-solution if I find the time. Looks promising at first hand ... and maybe I can use it. Saves me a lot of time when I don't have to manually print those received attachments.

  7. #7
    Djblois / Charlize

    Let me know if you need anything I can help with. Gladly do so.

    John

Posting Permissions

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