简体   繁体   English

如何使用VBA在Excel中打开(实际上打开)文本文件?

[英]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. 澄清一下-我不希望将数据从文本文件导入Excel。 I just want to open the text file from within Excel - but the actual edit of the text file will be in Notepad. 我只想从Excel中打开文本文件-但文本文件的实际编辑将在记事本中。

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 来源: 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 PS对不起,我目前在未安装excel的计算机上,所以直到星期一我才能对其进行测试...所以请尝试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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