我试图使用VBA从word打开.doc文件。它正在扩展,没有扩展。为什么? [英] I am trying to open .doc file from word using VBA. It is working with extension and without giving extension. Why?

查看:88
本文介绍了我试图使用VBA从word打开.doc文件。它正在扩展,没有扩展。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Documents.Open FileName:="C:\test", ReadOnly:=False



OR


OR

Documents.Open FileName:="C:\test.doc", ReadOnly:=False





我尝试了什么:





What I have tried:

Both the code works. Why do I have to give extension then?

推荐答案

Word的默认扩展名是.doc或.docx。这就是为什么...... Word为你完成了它。



但是,如果要在Excel VBA中运行完全相同的代码,它会查找.xls或.xlsx文件。



最好是明确的。例如..如果同时拥有test.doc和test.docx ...打开哪个文件将完全取决于哪个版本的Word运行VBA
The default extension for Word is .doc or .docx. That is why...Word has finished it off for you.

But, if you were to run exactly the same code in Excel VBA it would look for .xls or .xlsx files.

It's always best to be explicit. For example.. what if you have both a test.doc and a test.docx... which file is opened would then depend entirely on which version of Word was running the VBA


这篇关于我试图使用VBA从word打开.doc文件。它正在扩展,没有扩展。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆