Opening a txt file and copy all to excel using VBA

nkw2306

New Member
Joined
Jan 20, 2015
Messages
32
Office Version
  1. 2019
Platform
  1. Windows
Hello.

One of the systems I use will only do Txt files therefore there is no way round it.

I need a piece of code that will open a named txt file and copy the whole document into excel. I then need it to delimit it with the comma into readable cells.

Any help is appreciated.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
The good news is that it is easy to come up with most (if not all) of the VBA code you need - without having to write any of it!
Simply go into Excel, turn on the Macro Recorder, and record yourself opening and delimiting the file in Excel, and you will have most of the VBA code that does this.
The Macro Recorder is a great tool for these type of things - just record yourself doing it manually to get the VBA code you need.
 
Upvote 0
Hi Joe.

I have already tried this however I also need to the code that actually opens the txt file so I can copy it into excel.
 
Upvote 0
You can record that part too.

Just go into Excel, and open the file by going to the Data menu, and going to the "Get External Data" ribbon, select "From Text", and select your file.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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