How to close an open .txt file.

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
833
Office Version
  1. 365
Platform
  1. Windows
I have an open .txt file. I know where it is (path). How do I close it?

VBA Code:
Dim sPath as string

Dim sFileName as string

sPath = "C:\Users\Bob\Desktop\"

sFileName = "Test.txt"

Application.DisplayAlerts = False

Close sPath & sFileName
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Did you open the .txt file using VBA?

If so, then the easy way is to put that code and the code to close it in the same sub.

If not (which actually seems to be the case), the only way to close it is to close the application that's viewing it by accessing the Windows Task Manager with VBA. (So notepad, notepad++, etc.)

Please let us know which it is (and if the latter, the name of the application that your .txt file is opened in as it appears in Task Manager).
 
Last edited:
Upvote 0
I am trying to determine if I can help the person who made this post Close all Hyperlinked Files

They are trying to close files opened via hyperlinks that are in the workbook.

I'm guessing that the file was opened using associated programs. So .txt probably Notepad? (I use Notepad++ on my computer so I may have to change the association temporarily.) They say Word files too. Of course closing all excel files is easy.
 
Upvote 0

Forum statistics

Threads
1,214,807
Messages
6,121,679
Members
449,047
Latest member
notmrdurden

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