PDA

View Full Version : Reference Microsoft Word 16.0 Object Library



vloneboy
05-13-2019, 12:39 AM
Hey guys,

is there a way to automatically activate the reference Microsoft Word 16.0 Object Library somehow (with a code) ?

greetings,

YasserKhalil
05-13-2019, 01:25 AM
Try this code


Sub Add_Object_Library_Reference_By_GUID()
Dim strGUID As String


strGUID = "{00020905-0000-0000-C000-000000000046}" 'Microsoft Word
Rem strGUID = "{00020813-0000-0000-C000-000000000046}" 'Microsoft Excel
Rem strGUID = "{91493440-5A91-11CF-8700-00AA0060263B}" 'Microsoft PowerPoint
Rem strGUID = " {4AFFC9A0-5F99-101B-AF4E-00AA003F0F07}" 'Microsoft Access
Rem strGUID = " {00062FFF-0000-0000-C000-000000000046}" 'Microsoft Outlook

On Error Resume Next
ThisWorkbook.VBProject.References.AddFromGuid strGUID, 0, 0
On Error GoTo 0
End Sub

vloneboy
05-13-2019, 01:48 AM
It doesn't work unfortunately

YasserKhalil
05-13-2019, 01:57 AM
Where does you put the code (into Excel or Word) ..?
I suppose you put it into excel so as to add the Word Library

Make sure of References from Tools menu ...

vloneboy
05-13-2019, 02:06 AM
I'm transfering some data from excel to a word document, therefore I need to activate tis reference. But it should do it automatically.

vloneboy
05-13-2019, 02:59 AM
I'm getting the error "user-defined type not defined"

YasserKhalil
05-13-2019, 03:01 AM
May be you are using MAC .. I am not sure
On what line do you have the error?

vloneboy
05-13-2019, 03:19 AM
No I'm not.

The error is appearing in the line which says: Private Function TEST(ByVal T As Integer, wdDok As Document, I As Integer) As Boolean

But when I manually put in the word reference it works.

YasserKhalil
05-13-2019, 03:42 AM
May be you have to run the code I posted earlier first then run your code

vloneboy
05-13-2019, 03:43 AM
I tried it is on the top of my code, is there another possible to run it before everything else ?

Aflatoon
05-13-2019, 03:43 AM
Why do you need to add it programmatically? References are saved with the workbook.

If you need to support different versions of Word, it's far easier to late bind the code, especially as security settings can prevent you from altering references.

vloneboy
05-13-2019, 04:03 AM
The people who will use the code do not have good vba skills and probably don't know how to add the reference themself. Therefore it would be good if the reference would be added programmatically when they run my code.

Aflatoon
05-13-2019, 04:12 AM
I think you misunderstood. Once the reference is added to the workbook by you, it is saved with it. The users don't need to do anything.

vloneboy
05-13-2019, 04:17 AM
I understood that but they'll only import the code, the workbook differs each time

Aflatoon
05-13-2019, 04:42 AM
You're saying that they are capable of importing code but not setting a reference??

I still suggest you late bind the code as it's far simpler than any other option.

vloneboy
05-13-2019, 05:07 AM
and how does late binding work ?

Aflatoon
05-13-2019, 05:33 AM
Declare any Word variables as Object - eg
wdDok As Object - and declare any constants that you use from the Word object library.

Artik
05-20-2019, 03:40 AM
Adding references with the code requires that "programmatic access to the VBA project" be enabled. By default it is turned off.
Therefore vloneboy says:

It doesn't work unfortunately

Artik

NickWillson
07-17-2023, 06:57 AM
I've been using the Microsoft Word 16.0 Object Library for a while now, and it's been pretty handy. It's got some cool features that make my work easier.

LiamAllen
07-18-2023, 03:15 AM
Hey everyone! The library offers some seriously cool features. It's definitely worth exploring if you're into Word programming. The Word 16.0 Object Library has become my go-to resource, providing me with a solid foundation to build upon. It's amazing how much you can achieve with the right tools at your disposal.