Hey guys,
is there a way to automatically activate the reference Microsoft Word 16.0 Object Library somehow (with a code) ?
greetings,
Printable View
Hey guys,
is there a way to automatically activate the reference Microsoft Word 16.0 Object Library somehow (with a code) ?
greetings,
Try this code
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
It doesn't work unfortunately
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 ...
I'm transfering some data from excel to a word document, therefore I need to activate tis reference. But it should do it automatically.
I'm getting the error "user-defined type not defined"
May be you are using MAC .. I am not sure
On what line do you have the error?
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.
May be you have to run the code I posted earlier first then run your code
I tried it is on the top of my code, is there another possible to run it before everything else ?
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.
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.
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.
I understood that but they'll only import the code, the workbook differs each time
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.
and how does late binding work ?
Declare any Word variables as Object - eg- and declare any constants that you use from the Word object library.Code:wdDok As Object
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.
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.