View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default References in VBA (Tools - References)

Yes, you can create references programmatically on the fly. See

ThisWorkbook.VBProject.References.AddFromFile
ThisWorkbook.VBProject.References.AddFromGuid


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Alan" wrote in message
...
"Bob Phillips" wrote in
message


This is hypothetical of course, because no sane person would
ever do
this :-)).


Absolutely - it was in the spirt of academic interest only ;-

{Laughs maniacally}

Now, purely hypothetically, I wonder if you could you
programmatically
create a reference in the VBE on the fly?



Assuming that Excel is still standing after this, I don't
think you
would encounter any particular problems. But if you pass the
workbook to anyone else, and they don't have a particular file
referred to, they might well get problems.


So you mean, for example, if I have a reference to, say,
Outlook 9.0
(Outlook 2000) but the other person has Outlook 2003 (Outlook
11.0 ?)
installed on their machine (and not OL2000) , and therefore
MSOUTL9.OLB file does not exist on their machine, the workbook
might
throw a wobbly?



On the general issue, I have used 'late binding' - if that is
the
correct term - (CreateObject) to avoid the issue of other users
having
references set or not.

The only problem with that is you don't seem to be able to
explicitly
declare variables as type, and hence the intellisense does not
kick in
and help out which is a big downer for a relative VBA beginner
like
me.

I guess I could write the code using (early?) binding, then
finally
delete the DIM statements and use CreateObject rather than NEW
once I
am done.

Would that be regarded as 'best practice' in order to maximise
portability across machines?


Thanks for your interest!

Alan.


--
The views expressed are my own, and not those of my employer or
anyone
else associated with me.

My current valid email address is:



This is valid as is. It is not munged, or altered at all.

It will be valid for AT LEAST one month from the date of this
post.

If you are trying to contact me after that time,
it MAY still be valid, but may also have been
deactivated due to spam. If so, and you want
to contact me by email, try searching for a
more recent post by me to find my current
email address