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
A .wsf script can access the xl* constants via a Excel.Sheet reference:
type xlconst.wsf
<?xml version="1.0" standalone="yes" encoding="iso-8859-1" ?>
<package>
<job id="xlconst">
<reference object="Excel.Sheet" reference="true"/>
<script language="VBScript">
<![CDATA[
' ############################################################################
For Each arg In WScript.Arguments.Unnamed
WScript.Echo "Const " & arg & " = " & Eval(arg)
Next
' ############################################################################
]]>
</script>
</job>
</package>
output:
cscript xlconst.wsf xlNo xlYes
Const xlNo = 2
Const xlYes = 1
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.
How about using fully qualified name?
dim sourceType As Excel.XlListObjectSourceType
sourceType = Excel.XlListObjectSourceType.xlSrcRange
EDIT: (in vbscript)
dim sourceType
sourceType = 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.