Import Multiple Text Files from Folder to Multiple Worksheets formatted as TEXT

DarleneS

New Member
Joined
Dec 12, 2019
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
Hi –

I’m a SQL coder and just started coding in VBA so I don’t have all the tricks I need yet. I used the code in the below link to create a macro to import multiple text files from a folder into an Excel workbook on multiple sheets. This code is excellent and does what I need, except I am having a small issue that I need help with. When I import my text files into Excel they are populating as "General" format causing my leading zeros in some fields to be dropped. I created a text based template to open upon Excel launch, but it didn't work with this macro. Is there something I can add to my code to have my text files import to Excel as all “Text” and not “General”? Thanks for any help anyone can offer.

Import Multiple Text Files from a folder to multiple worksheets

Sub Import_Text_To_Sheets()
Dim FilesToOpen
Dim x As Integer
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Application.ScreenUpdating = False

FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Text Files (*.txt), *.txt", _
MultiSelect:=True, Title:="Text Files to Open")
If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
End If

x = 1
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
wkbTemp.Sheets(1).Copy
Set wkbAll = ActiveWorkbook
Cells(2, 1).Select
ActiveWindow.FreezePanes = True
Cells.EntireColumn.AutoFit
wkbTemp.Close (False)
x = x + 1

While x <= UBound(FilesToOpen)
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
With wkbAll
wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count)
Cells(2, 1).Select
ActiveWindow.FreezePanes = True
Cells.EntireColumn.AutoFit
End With
x = x + 1

Wend
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi, please try to use Power Query to do it this job, put all data in the same place and then you can filter what you want
 
Upvote 0
Hi, please try to use Power Query to do it this job, put all data in the same place and then you can filter what you want
I don't think Power Query will work for what I need. All the research I have done on Power Query appends all the files into the same worksheet, I need each file to be on a different worksheet.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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