vba VBA中的正常打开文件语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21911495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Normal open file statement in VBA
提问by Julius
I′m trying to open a file but it′s not working.
我正在尝试打开一个文件,但它不起作用。
Workbook.Open C:\users\me\desktop\testfile.txt
I always get the error message: Run-time error '424': Object required
我总是收到错误消息:运行时错误“424”:需要对象
I just want to open a file. It′s not fixed if the file will be a exel, a txt, jpg or word file.
我只想打开一个文件。文件是exel、txt、jpg 或word 文件是不固定的。
Should be as simple as possible.
应该尽可能简单。
回答by Albert D. Kallal
To open a word, excel, jpg, pdf or any file, simple use:
要打开一个 word、excel、jpg、pdf 或任何文件,简单使用:
Application.FollowHyperlink "path to file name"
回答by Mike
Create an Excel object first:
首先创建一个 Excel 对象:
Dim xl as New Excel.Application
xl.Workbooks.Open("C:\users\me\desktop\testfile.txt")
xl.Visible = True