简体   繁体   中英

How do you open (actually open) a text file in Excel using VBA?

I know how to read/write from/to a text file. But those routines don't actually visibly open the text file. I want to be able to open the text file so I can make edits directly (in the Notepad application), rather than through a macro.

To clarify - I am not looking to import the data from the text file into Excel. I just want to open the text file from within Excel - but the actual edit of the text file will be in Notepad.

Have you tried it like this:

Sub OpenTextFile() 

On Error GoTo 1 
ActiveWorkbook.FollowHyperlink "C:\Windows\test.txt", NewWindow:=True 
Exit Sub 
1:       MsgBox Err.Description 

End Sub

Source: http://www.vbaexpress.com/kb/getarticle.php?kb_id=341

PS Sorry, I'm currently on a machine without excel installed, so I can't test it until monday...so please try it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM