dakiquang
dakiquang

Reputation: 694

How to define const as an object in Excel VBA?

I have an object

xmlHttp = CreateObject("MSXML2.xmlhttp")

How can I store this object( xmlhttp Object) as a const?

Example

Public xmlHttp As ... = CreateObject("MSXML2.xmlhttp")

Upvotes: 2

Views: 3695

Answers (2)

Harry Steinhilber
Harry Steinhilber

Reputation: 5239

Objects cannot be Const. Only primitive types like Integer can. Also, VBA does not have the notion of a read-only field. You can sort of mimic this though by using a private field in a module and a Public Property Get Xmlhttp() on that module.

Upvotes: 5

JMax
JMax

Reputation: 26591

As Harry pointed out, Objects cannot be Constants.

Yet, you may consider using classes to simulate this behavior and a read-only field. See this article on Chip Pearson's website to learn more about classes.

Upvotes: 2

Related Questions