vba - TransferSpreadsheet acImport 默认为文档文件夹 - 运行时错误 3011 (Access VBA)
问题描述
使用 DoCmd.TransferSpreadsheet acImport 目前对我不起作用。我正在尝试导入 .xlsx 文件并使用通配符 (*) 来完成文件名。当我使用 MsgBox 时,FullPath 是正确的,但是当 TransferSpreadsheet 运行时,它说它在 C:\Users\Me\Documents (默认位置)中找不到文件。
Dim FPath As String
Dim FName As String
Dim FullPath As String
FPath = CurrentProject.Path & "\Data\"
FName = "DataTable"
FullPath = Dir(FPath & FName & "*.xlsx")
If FullPath <> "" Then
DoCmd.TransferSpreadsheet acImport, 10, TableName, FullPath, 1
Else: MsgBox "Error - file not found"
End If
为什么它不在我指定的地方寻找?这个错误是否不正确并且它表明其他东西?
解决方案
Dir()
只返回一个文件名或什么都不返回(空字符串)。它不返回完整路径。
Dim FPath As String
Dim FileName As String
FPath = CurrentProject.Path & "\Data\"
FileName = Dir(FPath & "DataTable*.xlsx")
If FileName <> "" Then
DoCmd.TransferSpreadsheet acImport, 10, TableName, FPath & FileName, 1
Else
MsgBox "Error - file not found"
End If
推荐阅读
- spring-boot - 如何通过在 spring-boot 中从 bootstrap.yml 中获取名称来在 log4j2 中记录应用程序名称?
- javascript - 在 Typescript 中正确模拟 fetch
- java - 如何在Android中禁用对话框按钮?
- c - 评估和打印键盘输入作为双重
- android - 如何在 android webview 应用程序中实现应用程序购买?
- c++ - 如何将 unique_ptr 的移动构造函数和运算符实现为类的私有成员
- sql - Docker docker-entrypoint-initdb.d 按定义的顺序执行
- node.js - 如何将 nuxt.js 与 node 和 expressjs 一起使用
- d3.js - D3 lineRadial 不显示,而其他元素显示
- javascript - JQuery在第一次结束时调用动画函数