Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Documents.Open FileName:="C:\test", ReadOnly:=False

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?
Posted
Updated 6-Mar-19 10:47am
Comments
[no name] 6-Mar-19 16:39pm    
What happens if there is test.doc AND (test.txt OR test.pdf) in the same folder?
MadMyche 7-Mar-19 7:58am    
... or Test.doc AND Test.docx?
dirtyshooter 7-Mar-19 12:45pm    
if there are multiple files, it will take .doc as default.

1 solution

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
 
Share this answer
 
v2
Comments
dirtyshooter 6-Mar-19 19:18pm    
I agree. So the default extension for word is .doc and excel is .xls. If you have any other extension, it will not recognize. Even .docx or .xlsx

Nice to know man. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900