Problem with putting an "TxT" file help fast!!!

Ohmnus

New Member
Joined
Jul 23, 2018
Messages
1
Hi, i had an issue in my job, i have to load an .txt file to excel but i can't get it to work help, the route it's fine and the msgBox displays the txt file, but the Open functions says err 53 not found...
Code:
Sub OpenTextFile()

Dim FilePath As String
FilePath = Dir(Application.ThisWorkbook.Path & "\bases\*.*")
MsgBox "" & FilePath


Dim TextLine
Open "" & FilePath For Input As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]  ' Open file.
Do While Not EOF(1) ' Loop until end of file.
 Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , TextLine ' Read line into variable.
 Debug.Print TextLine ' Print to the Immediate window.
 MsgBox "" & TextLine
Loop
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]  ' Close file.


End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
try this:

Rich (BB code):
Sub OpenTextFile()

Dim FilePath As String
FilePath = Dir(Application.ThisWorkbook.Path & "\bases\*.*")
cd filepath

fName = Application.GetOpenFilename("Text Files (*.csv), *.csv")
If fName = "False" Then Exit Sub

Dim TextLine
Open fName For Input As #1   ' Open file.

...

hth,
Ross
 
Upvote 0
FilePath will only have the filename, you need to include the path when opening the file.
Rich (BB code):
Open Application.ThisWorkbook.Path & "\bases\" & FilePath For Input As #1   ' Open file.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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