If you read it as condescending, it wasn't meant to be. We can only go on
what you tell us. You said I already have an activeworkbook - yet you don't
in your initial code that you show - that indicated to me that your program
is operating from excel. It is not unusual for people to attempt to use
createobject from inside Excel and it is usually because they don't
understand that they don't need to. Anyway, If that is not the case, then
tell us from what application you are automating Excel and what you are
trying to accomplish other than turning calculation off in the new instance
of excel.
It was from the context of not needing it inside excel that I said a rule of
thumb is don't use it if you don't know that you need it. Your first
question was not about when to use Get vice create. From your first
question it appeared you didn't need to use either. That was the context of
my answer.
The first sentence was to explain why someone would answer you in the
context of needing to use createobject when in fact the real answer might be
that it doesn't need to be used at all and the answer is as simple as what I
gave. It was not meant to mean that you, Cheers, don't know what you are
doing.
Sorry, but I don't have time to war game every response on how it might be
interpreted. If you want turnkey explanations, perhaps use the help file
more. That is where I learned how to use GetObject and CreateObject and I
believe it does an excellent job. What it may not do as well is say when
you might or might not need either.
so again, what application are you trying to automate Excel from and what
are you trying to do.
so what is the key bit of information you provided:
the subject which didn't seem to have anything to do with your post since
you were not using the constant but providing the value of the constant amd
experiencing an error. The fact that you said you already have an
activeworkbook but no evidence of such in your code. the fact that you said
your purpose was to speed up an operation, but there were no operations
going on in your code. The fact that your first question was not about the
choice between GetObject or CreateObject. So when you tell me I didn't take
the time to understand the question, I took a lot of time to try to
understand the question - perhaps I read too much into the diverse clues you
dispersed.
And then again you may say my answer is condescending because you didn't
take the time to try to understand it.
If you really feel that being scolded for an opening statement like,
"When you use CreateObject, people assume you know what you are
doing..." requires you to "wargame" your responses, well so be it. If
you say it wasn't meant condescendingly, I'll take your word for it.
Over the past two days, I've been asking about late binding in the
context of avoiding having to load references programmatically when I
port my add-in to different machines. It is my understanding that if
you use late binding, for whatever reason, you must use the value of
the constant not the constant itself. At the time of my post, I
believed I was making some error in the value of the particular
constant I was using, so my subject actually quite accurately
represented my post.
The routine "AllOff" was designed to turn alerts off and
screenupdating off; very common, as you know, when you're trying to
speed things up. The fact that I didn't articulate which operations I
wanted to speed up is irrelevant.
What I asked, after Rob pointed out that I needed an active workbook,
was the difference between GetObject and CreateObject. What I got
instead was a discussion of how I probably didn't need to use either.
So, OK, perhaps you read my question correctly, but decided not to
answer that question, but rather another one that I didn't ask.
One reason for using late binding and CreateObject is to solve
Automation problems - running instances of Excel from some other
application. Strictly speaking, I'm not doing that; I'm trying to
avoid having to programmatically load libraries like "MSXML v3.0."
when I distribute my add-in. But, the effect is the same: I need an
object representing an (existing, in this case) instance of Excel that
I can then use to refer to child objects, properties, and methods. So,
yes, I get it that under normal circumstances from within Excel I
wouldn't need either Get or Create. But I'm not just going to be using
this on my machine, a point I've been making since bringing up late
binding issues in my first post.