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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:04:08  来源:igfitidea点击:

Normal open file statement in VBA

vbams-accessaccess-vbams-access-2010

提问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

回答by Sathish Kothandam

Are you trying to open the text file in excel ..

您是否正在尝试在 excel 中打开文本文件 ..

Then use opentextfunction

然后使用opentext函数

example

例子

Workbooks.OpenText ("C:\users\me\desktop\testfile.txt")