vba code: text to excel

mrinal saha

Board Regular
Joined
Jan 20, 2009
Messages
229
Hi folks,

Help me with a code to match the name of text files (16) in a folder with the tab name in an excel. If name matches, pull the data from text file and paste it in excel sheet with the same name.

Thanksss,
Mrinal
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hey Folks,,

I have figured out a code to match the text file with excel sheet name.but not able to open thetext file. Error in red line.

Sub Read_text_File()
Dim fso, fld, fil As Object
Dim fldpth As String

fldpth = "C:\Documents and Settings\287940\Desktop\Test Macros1\VBA Proj\Amlesh - Naveen\PDF\Page Center Reports"
Set fso = CreateObject("scripting.filesystemobject")
Set fld = fso.getfolder(fldpth)
For Each fil In fld.Files
fname = fil.Name

For i = 1 To Sheets.Count

If ActiveWorkbook.Sheets(i).Name = Left(fname, InStr(fname, ".") - 1) Then
Workbooks.OpenText Filename:="fldpth & fname" & strng & ".txt", _
Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= _
Array(0, 2), TrailingMinusNumbers:=True

End If
Next i
Next fil
End Sub

Thanks,
Mrinal
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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