PDA

View Full Version : [SOLVED:] Selecting Word reference library



Dave
03-19-2005, 12:27 PM
Can vba code be used to find out if a reference to the Word library has been made and if it has not been made then select the reference? I would imagine that a certain error production would indicate a missing reference but I'm looking for a more direct approach. Also the problem of Word libraries having different numbers with different XL versions seems to make this difficult. I'm looking for suggestions other than late binding. if you have any, I sure would appreciate any assistance. Dave

Jacob Hilderbrand
03-19-2005, 01:13 PM
See if these Kb Entries are of any use to you.

Determine the File Path or GUID to a VBA Reference Library (http://www.vbaexpress.com/kb/getarticle.php?kb_id=278)

Add a VBA Reference Library via code (http://www.vbaexpress.com/kb/getarticle.php?kb_id=267)

JonPeltier
03-19-2005, 10:00 PM
Dave -

What's the earliest version of Office your users will be using? As much as it may hurt to go backwards, you must develop in that version on a computer that has no later versions installed on it, if you refuse to late bind. Set a reference to the Word library on that computer. If the Excel program is opened in the same version you're using, you're fine. If it's opened in a later version, the reference is automatically changed to the version you've opened on.

If the file is developed in an earlier version, opened in a later version, then reopened in the earlier version, your references will break. This situation calls for late binding.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

Dave
03-20-2005, 12:14 AM
Jake and Jon it seems there is a juxtaposition between your posts. There seems to be hope and then there's reality. Well you know that this question is related to that post at that other site, late binding seems to be out. By the way, that code needs a bit of adjustment for group selections across pages. Jake thanks for those links. I'll hope and mess around with some code. Jon your right... all I'm going to do is crash my computer. The utility of this routine for me causes some niaeve optimism. I'll post if I come close. The help with this is truly appreciated. I'm open to any suggestions. Dave

Jacob Hilderbrand
03-20-2005, 12:23 AM
What exactly is the problem with using Late Binding in this case?

Dave
03-20-2005, 12:59 AM
Here's a link http://www.mrexcel.com/board2/viewtopic.php?t=136269&highlight=
Problem is the code here doesn't work unless a reference is set to the Word library. It's the expand paragraph line which errors out without the reference. I'm guessing that in this case, being that each line is a paragraph, I don't actually have to expand the paragraph, I only have to select the found line and perhaps avoid the reference. If that fails, back to trying to crash the puter. Thanks. Dave

TonyJollans
03-20-2005, 05:43 AM
I've just scanned the other threads here and there and the main problem appears to be solved. I don't, however, see any reason not to use late binding - early binding is required in order to use the wdParagraph constant, but hard coding its value of 4 instead would allow late binding.

Dave
03-20-2005, 12:21 PM
Thanks Tony. I've updated the post at the previous link but I still haven't figured out how to get rid of the reference. It seems I just need to set a range to the paragraph with the found selection to avoid using the expand code. Doesn't seem to want to work for me yet. I'm not sure if I follow your suggestion? Dave

JonPeltier
03-20-2005, 12:59 PM
Part of Early Binding is the use of descriptive constant names, such as wdParagraph, which are part of the object model, and represent numeric, difficult to remember values, such as 4.

When you convert from Early to Late Binding, you must convert all he named constants into their numerical equivalents. You can find their equivalents in the Object Browser, or simply by asking in the Immediate Window:

?wdParagraph
4

I don't know if this is what you were asking, but it sounded as though you were unsure of Tony's suggestion. I haven't read your code; unless I print it out and scribble all over it with a pencil, trying to read large blocks code gives me a headache!

- Jon

Anne Troy
03-20-2005, 01:02 PM
That's the first *real* tip I've seen on early -vs- late, Jon. Perhaps THAT (early -vs- late) is an article you could write (and we'd LOVE to have) in our articles section? :)

JonPeltier
03-20-2005, 04:22 PM
I have a small page on my web site:

http://peltiertech.com/Excel/EarlyLateBinding.html

I'm usually pretty retentive about listing them in my posts, but this time it slipped my attention.

Do you mind rehashed examples among your articles? I could probably add a quick list of pros and cons to help users decide which to use, as well as the description of its behavior across different Office versions.

- Jon

Dave
03-21-2005, 04:23 PM
This has been a great learning adventure. I'm looking forward to reading the article. Apologies for the code eye strain. I'll post a solved to this thread. However, if anyone has any other relevent information, I would like to encourage them to post. The links and threads have been very informative(if you ignore my eyesore). Many thanks! Dave