How to save Multiple Imported text files to a single sheet using VBA

zaska

Well-known Member
Joined
Oct 24, 2010
Messages
1,046
Hello,

I have recorded a macro to import text file. I want to run this macro to import more than one text file and save them into a single sheet. I tried using For Next Loop...which is running the macro sequence again..but i am clueless about the syntax on how to save the imported files one after the other ..

Could anyone help me?

The below is the macro which i have recorded and added for next loop...please tell me how to save the text files in the same sheet and run the macro again to save the next one and other text files ?

Code:
<code> Sub Macro()
      For i = 1 to 5
      Workbooks.OpenText Filename:=Application.GetOpenFilename("Text,*.txt"), _
        Origin:=437, StartRow:=4, DataType:=xlFixedWidth, FieldInfo:=Array( _
        Array(0, 4), Array(6, 1), Array(11, 1), Array(34, 1), Array(100, 1), ( _
        TrailingMinusNumbers:=True
     Next i
     End Sub</code>


Note : This query is cross posted at How to run Loop in VBA to import more than one file

Thank you
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Is there any thing wrong with my post or didn't i communicate it properly?

Thank you.
 
Upvote 0

Forum statistics

Threads
1,215,886
Messages
6,127,578
Members
449,385
Latest member
KMGLarson

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