【问题标题】:Using FileSystemObject in Access VBA在 Access VBA 中使用 FileSystemObject
【发布时间】:2013-10-29 01:24:59
【问题描述】:

我使用的是 Access 2010,这是我的参考库和 Access VB IDE 中可用的 FileSystemObject 方法的屏幕截图:


当我启动这个对象时,我似乎无法访问熟悉的方法,因为这个示例调试结果出现异常:


我还使用显式声明和初始化变量来获得相同的结果。

有什么想法可能是错的吗?


要重播@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", ";")

【问题讨论】:

  • 错误信息是什么意思?
  • 它说“路径无效”,尽管文件存在。我现在将代码测试为 VBS,并且 WSH 也报告了相同的错误。但是,如果我打印 p 变量并将字符串放在 Windows 运行对话框文件中,则会按预期打开。驱动器是 USB 的,但这没关系...
  • 向我们展示 p 中的完整路径
  • 我用实际数组更新了这个问题,并希望跟踪这个问题,因为我没想到 VBS 会出现同样的问题。谢谢
  • 可能是您将“f:\temp\test\op1\gev_final_1.xlsx”传递给GetFolder()GetFolder() 抱怨因为没有文件夹 用那个名字? (假设“f:\temp\test\op1\gev_final_1.xlsx”实际上是一个file....)

标签: ms-access vba ms-office


【解决方案1】:

这里的问题是 GetFolder() 被传递了一个包含 file 完整路径的字符串,并且它正确地抱怨这样的 文件夹 不存在。如果您想提取特定 file 所在的 文件夹,那么您可以使用类似

fso.GetFile("C:\Users\Public\Database1.accdb").ParentFolder

【讨论】:

    猜你喜欢
    • 2011-03-15
    • 2015-10-12
    • 2022-12-19
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多