vba DoCmd.TransferSpreadsheet 无法识别工作表名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17350789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DoCmd.TransferSpreadsheet is not recognizing worksheet name
提问by sigil
I'm trying to import a sheet from an Excel workbook using DoCmd.TransferSpreadsheet
. The sheet's name is XYZ Priority
.
我正在尝试使用DoCmd.TransferSpreadsheet
. 工作表的名称是XYZ Priority
。
I'm calling the method as follows:
我按如下方式调用该方法:
DoCmd.TransferSpreadsheet FileName:=filePath, tablename:="XYZ", _
hasfieldnames:=True, range:="[XYZ Priority]!"
I get this error message:
我收到此错误消息:
'[XYZ Priority]$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long.
It appears that the space is what's causing the problem. I've tried several different ways to identify the range, with and without exclamation points, and all have failed:
看来空间是导致问题的原因。我尝试了几种不同的方法来识别范围,带和不带感叹号,但都失败了:
"XYZ Priority"
"XYZ_Priority"
"'XYZ Priority'"
How can I correctly pass the sheet to TransferSpreadsheet
?
我怎样才能正确地将工作表传递给TransferSpreadsheet
?
采纳答案by HansUp
Use just the sheet name followed by the $
sign.
仅使用工作表名称后跟$
符号。
DoCmd.TransferSpreadsheet FileName:=filePath, TableName:="XYZ", _
HasFieldNames:=True, Range:="XYZ Priority$"