在Access VBA中使用FileSystemObject

3
我正在使用Access 2010,这是我在Access VB IDE中引用库和可用FileSystemObject方法的截图: enter image description here 当我启动此对象时,似乎无法访问熟悉的方法,我得到了这个例外,如下面的调试结果所示: enter image description here 我还使用了明确声明和初始化变量来获得相同的结果。
有什么想法可能出了问题?
回复 @4dmonster 的评论,这是实际的数组:
For Each p In Split("f:\temp\test\op1\gev_final_1.xlsx;f:\temp\test\op1\gev_final_2.xlsx;f:\temp\test\op1\gev_final_3.xlsx;f:\temp\test\op1\gev_final_4.xlsx;" & _
                     "f:\temp\test\op1\gev_final_5.xlsx;f:\temp\test\op1\gev_final_6.xlsx;f:\temp\test\op1\gev_final_7.xlsx;f:\temp\test\op2\gev_final_8.xlsx;" & _
                     "f:\temp\test\op2\gev_final_9.xlsx;f:\temp\test\op2\gev_final_10.xlsx;f:\temp\test\op2\gev_final_11.xlsx;f:\temp\test\op2\gev_final_12.xlsx;" & _
                     "f:\temp\test\op2\gev_final_13.xlsx;f:\temp\test\op3\gev_final_14.xlsx;f:\temp\test\op3\gev_final_15.xlsx;f:\temp\test\op3\gev_final_16.xlsx;" & _
                     "f:\temp\test\op3\gev_final_17.xlsx;f:\temp\test\op3\gev_final_18.xlsx;f:\temp\test\op3\gev_final_19.xlsx;f:\temp\test\op4\gev_final_20.xlsx;" & _
                     "f:\temp\test\op4\gev_final_21.xlsx;f:\temp\test\op4\gev_final_22.xlsx;f:\temp\test\op4\gev_final_23.xlsx;f:\temp\test\op4\gev_final_24.xlsx;" & _
                     "f:\temp\test\op5\gev_final_25.xlsx;f:\temp\test\op5\gev_final_26.xlsx;f:\temp\test\op5\gev_final_27.xlsx", ";")

错误信息说什么? - Gord Thompson
它显示“路径无效”,尽管文件存在。我现在已经将代码测试为VBS,WSH也报告了相同的错误。但是,如果我打印 p 变量并在Windows运行对话框中输入字符串,则文件将如预期一样打开。驱动器是USB,但这不应该有影响... - theta
在程序中展示完整路径。 - 4dmonster
我已经使用实际数组更新了问题,并希望能够跟踪此问题,因为我没有预料到在VBS中会出现相同的问题。谢谢。 - theta
1
可能是你正在将 "f:\temp\test\op1\gev_final_1.xlsx" 传递给 GetFolder(),而 GetFolder() 抱怨没有这个名称的文件夹?(假设 "f:\temp\test\op1\gev_final_1.xlsx" 实际上是一个文件....) - Gord Thompson
就是这样,谢谢。我以为 GetFolder 需要完整路径并返回其文件夹。对于此次打扰,非常抱歉... - theta
1个回答

4
这里的问题在于GetFolder()被传递了一个包含完整文件路径的字符串,它正确地抱怨这样的文件夹不存在。如果你想提取特定文件所在的文件夹,那么你可以使用类似以下的内容:
fso.GetFile("C:\Users\Public\Database1.accdb").ParentFolder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接