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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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