Jump to content

CreateObject statement using variable instead of string literal

John Browne

Recommended Posts

  • Mobilize.Net Staff

Visual Basic supports a way to call external classes with the CreateObject() function. The function takes a class name as a parameter. Here's an example:

Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")

In this case, the parameter for the function is a string literal ("Excel.Sheet") and the VBUC will migrate the VB6 code correctly. 


Suppose you have this VB6 code:

Const XL = "Excel.Sheet"
[some code]

In this case the VBUC will display the error "CreateObjects statements using a variable instead of a literal string" in the output code. This is because the value of the variable "foo" can change over time. In this case, it's advisable to replace the variable in the CreateObject syntax with the actual name of the object class being called:


Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use