“您输入的名称无效" Excel错误 [英] "The name that you entered is not valid" error with Excel

查看:267
本文介绍了“您输入的名称无效" Excel错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个简单的VBScript示例(不是Excel宏),并遇到了您输入的名称无效问题.

I'm trying to run a simple VBScript example (not an Excel macro) and have run into the The name that you entered is not valid issue.

名称带有下划线,没有空格,并且工作簿是全新的(名称管理器未显示任何内容).此外,尽管大多数网络示例都显示:=对我来说是语法错误.

The name has an underscore, no spaces, and the workbook is brand new (the Name Manager shows nothing). Also, although most web examples show := that is a syntax error for me.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\test.xlsx")

'This line fails
objExcel.ActiveWorkbook.Names.Add Name="_myRange", RefersTo="Sheet1!$A$1:$D$3"

objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Echo "Finished."
WScript.Quit  

有什么想法吗?

推荐答案

Name:="_myRange"语法是命名参数语法.如您所见,您不能在VBScript中使用它.但是,您不能简单地将其更改为Name="_myRange". Name="_myRange"将导致FALSE,因此您尝试使用FALSE作为名称.那就是为什么会出错.

The Name:="_myRange"syntax is the named arguments syntax. As you observed right, you cannot use this with VBScript. But then you cannot simply change it to Name="_myRange". Name="_myRange" will result in FALSE and so you are trying to use FALSE as a name. Thats why the error.

您必须按正确的顺序排列参数,而不要命名它们.

You must put the arguments in their right order without naming them.

objExcel.ActiveWorkbook.Names.Add "_myRange", "=Sheet1!$A$1:$D$3"

哦,引用必须以=开头.

这篇关于“您输入的名称无效" Excel错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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