PDA

View Full Version : Importing a Text File



Djblois
04-17-2007, 11:09 AM
I am using this code to ask the user which text file to open:

If Not Application.Dialogs(xlDialogImportTextFile).Show Then

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?

Norie
04-17-2007, 12:10 PM
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?
The only line I need to set is 49.

jolivanes
04-17-2007, 01:29 PM
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

Charlize
04-17-2007, 02:34 PM
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

JohnTake a look at this. Solution provided by VBAX site with full coding sample :whistle: .

http://vbaexpress.com/forum/showpost.php?p=96669&postcount=6

Charlize

jolivanes
04-17-2007, 03:42 PM
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

Charlize
04-18-2007, 12:21 AM
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.
JohnThe 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.

jolivanes
04-18-2007, 08:03 AM
Djblois / Charlize

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

John