Reading a text file (.txt) into current workbook, NOT loading as new workbook

JR_Chicago

New Member
Joined
Apr 20, 2010
Messages
23
Hey folks... I have two tab delimited text files that I'm trying to read into an Excel workbook which I've already created...

I've been unable to find the code for reading a text file into an existing workbook, rather, the book I am using, "Writing Excel Macros with VBA" by Steven Roman only has examples for loading text files as NEW workbooks.

I've been successful in loading the text files as new workbooks using the following code:

Code:
Sub ReadInTextFiles()
Workbooks.OpenText _
    Filename:="E:\New Folder\__New_Product_File.txt", _
    Origin:=xlWindows, _
    StartRow:=1, _
    DataType:=xlDelimited, _
    TextQualifier:=xlTextQualifierNone, _
    ConsecutiveDelimiter:=True, _
    Tab:=True, _
    FieldInfo:=Array(Array(1, 2), Array(2, 1), Array(3, 1), Array(4, 1))
End Sub

As I said, when I run this macro from the current workbook it opens a new instance of Excel and populates the values from the text file in that workbook.

I want to read both text files into my current workbook.

Anyone know how to do that?

Thanks.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Look in the menu at DATA > Import External Data > File Type: Text.

This wizard lets you import a text file, set all the import settings and column type, then select whether the data comes into a specific cell on a specific sheet or as a new worksheet. Either way, it comes into the current workbook.

You should be able to record your desired settings/usage and tweak that into a permanent macro.
 
Upvote 0
This definitely helps, unfortunately, I need to be able to automate this task (reading in the files) with VBA as it is a task that will be repeated many times on an intraday basis.

The end user of the workbook will not have time to use the import wizard.

Are you familiar with how to execute this task in code?
 
Upvote 0
Nevermind... I didn't realize you had indicated to record a macro while using the wizard. That works... Thanks
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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