Stuck on open file.

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
Here is a bitof my script. It runs once just fine but if i run it a second time before shutting down the workbook I get an error "File already in open" on line 1. Which file and how can i close it?

Open "C:\Users\test user\AppData\test.txt" For Input As #1
Do While Not EOF(1)
Line Input #1 , ltxt
If ltxt = "bob b" Then GoTo xit
Loop
Close #1


thanks...
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Are you closing the file in the code you jump to when you find the text you are looking for?
 
Upvote 0
Do you mean this?

Open "C:\Users\test user\AppData\test.txt" For Input As
#1

As far as I can see it is not actually open.

I have tried to close it just in case but I can not find the syntax that works.

Any help would be appreciated

 
Upvote 0
I found the issue. Seems I was only closing the file in one instance:

Open "C:\Users\test user\AppData\test.txt" For Input As
#1

Do While Not EOF(1)
Line Input
#1
, ltxt
If ltxt = "bob b" Then GoTo xit ' needed to close file there as well.
Loop
Close
#1
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,619
Members
449,039
Latest member
Mbone Mathonsi

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