can I Import Multiple Fixed Width Files at once

kat50

New Member
Joined
Aug 8, 2009
Messages
3
Is it possible to import multiple fixed with files at once? I can make the following work, but I do not know how to allow the user to search for a file.


Sub OpenTextFile()

Const xlFixedWidth = 2
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.OpenText _
"C:\Users\Kate\Desktop\Test.txt", , , xlFixedWidth, , , , , , , , , Array(Array(0, 1), Array(4, 1), Array(9, 1), Array(23, 1), Array(30, 1), Array(33, 1), Array(42, 1), Array(48, 1), Array(51, 1), Array(54, 1), Array(64, 1), Array(70, 1), Array(80, 1))

End Sub

Thank you so much!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You could use Application.GetFileName to allow the user to select a file/files.

If you do want to import multiple files then there is no way to do it 'at once'.

You would need to loop through all the files and import them as required.

By the way where are you running this code from, is it Excel?

If it is why are you creating another instance of Excel here?:)
Code:
Set objExcel = CreateObject("Excel.Application")
 
Upvote 0
Thanks for the quick reply.

I am doing this in excel. I was trying to mimic an example I found on the Tech Net site...

if I use: Application.GetFileName can you tell me where I should stick that in the module?

Thanks so much!
 
Upvote 0
Not quite sure since I don't know exactly what you want to do.

I suppose the obvious answer is you put it where you want the users to be able to select the file(s).:)
 
Upvote 0
Sorry I am not that savvy. I would like the user to be able to browse to the file that is being imported. This module parses the data as needed, but I have hard keyed the file name. Can you advise on correcting that?

I really appreciate your help!
 
Upvote 0

Forum statistics

Threads
1,215,851
Messages
6,127,291
Members
449,374
Latest member
analystvar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top