如何使用 OLE 引用内置 MS Excel 类型
我的应用程序应该在 Excel 中执行一些简单的操作,例如添加图表、列表对象等。我正在使用 OLE 连接。问题是,某些 Excel 方法采用内置类型(枚举)作为参数。我对提及它们没有任何想法。例如:
WorkBook.ActiveSheet.ListObjects.Add(xlSrcRange, Range("$D$5:$J$15"), , xlNo).Name = "Table1"
xlSrcRange和xlNo属于内置枚举。我尝试按以下方式引用它们
ExcelApp.xlSrcRange
ExcelApp.XlListObjectSourceType.xlSrcRange
ExcelApp.XlListObjectSourceType
此代码会导致错误“对象不支持属性或方法ExcelApp.xlSrcRange”
New XlListObjectSourceType.xlSrcRange
new xlSrcRange
此代码也会导致错误(未知变量XlListObjectSourceType和xlSrcRange)
我使用QTP,脚本语言是VB-script
my application should perform some simple actions in Excel, like adding charts, list objects and so on. I'm using OLE connection. The problem is, that some Excel methods taking built-in types (enumerations) as arguments. And I have no ideas about referring to them. For example:
WorkBook.ActiveSheet.ListObjects.Add(xlSrcRange, Range("$D$5:$J$15"), , xlNo).Name = "Table1"
xlSrcRange and xlNo belong to the built-in enumeration. I tried to refer to them in a following way
ExcelApp.xlSrcRange
ExcelApp.XlListObjectSourceType.xlSrcRange
ExcelApp.XlListObjectSourceType
this code causes error "Object doesn't support property or method ExcelApp.xlSrcRange"
New XlListObjectSourceType.xlSrcRange
new xlSrcRange
this code causes an error too (unknown variable XlListObjectSourceType and xlSrcRange)
I'm working with QTP and the script language is VB-script
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.wsf 脚本可以通过 Excel.Sheet 引用访问 xl* 常量:
输出:
普通 VBScript 不能。如果 QTP 仅限于纯 VBScript,则您必须手动添加/定义常量。也许上面的 .wsf 会让这个任务变得更容易。
A .wsf script can access the xl* constants via a Excel.Sheet reference:
output:
Plain VBScript can't. If QTP is restricted to plain VBScript, you'll have to add/define the constants manually. Perhaps the above .wsf will make this task easier.
使用完全限定名称怎么样?
编辑:(在 vb 脚本中)
How about using fully qualified name?
EDIT: (in vbscript)