VBA Dir功能不能在Excel 2010上工作 [英] VBA Dir function not working on Excel 2010

查看:308
本文介绍了VBA Dir功能不能在Excel 2010上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用文件资源管理器映射了Intranet位置。即将 http://intranet.XXXXXXX.com/mydir/ 映射到M:\



我正在使用 Dir 函数来测试该位置中是否存在一个文件:

  Dim FileExists as Boolean 

FileExists = Dir(M:\myfile)<

如果FileExists Then MsgBox在M中找到的文件:

我在Excel 2007上运行该宏,它工作正常。当我在Excel 2010上运行它时,即使该文件存在于指定的位置, Dir(M:\myfile)始终返回。我找不到两个Excel版本的解决方案。任何想法?

解决方案

您可以在文件路径末尾添加文件扩展名作为通配符。我在excel 2010中试了一下,它为我工作。

  Dim FileExists As Boolean 
FileExists = Dir( D:\myfile&* .txt)<>

如果FileExists Then MsgBox在M中找到的文件:


I mapped an intranet location using the File Explorer. i.e. mapped http://intranet.XXXXXXX.com/mydir/ to M:\

I'm using the Dir function to test if a file is present in that location:

 Dim FileExists as Boolean

 FileExists = Dir("M:\myfile") <> ""

 If FileExists Then MsgBox "File found in M:"

I run that macro on Excel 2007 and it Works Fine. When I run it on Excel 2010 though, Dir("M:\myfile") always returns "", even if the file is present in the specified location. I can´t find a solution that will work on both Excel versions. Any ideas?

解决方案

You may add file extension as a wildcard character at the end of filepath. I gave a try in excel 2010 and it worked for me.

  Dim FileExists As Boolean
    FileExists = Dir("D:\myfile" & "*.txt") <> ""

    If FileExists Then MsgBox "File found in M:"

这篇关于VBA Dir功能不能在Excel 2010上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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