Consulting

Results 1 to 20 of 20

Thread: Reference Microsoft Word 16.0 Object Library

  1. #1
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location

    Reference Microsoft Word 16.0 Object Library

    Hey guys,

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

    greetings,

  2. #2
    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

  3. #3
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location
    It doesn't work unfortunately

  4. #4
    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 ...

  5. #5
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location
    I'm transfering some data from excel to a word document, therefore I need to activate tis reference. But it should do it automatically.

  6. #6
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location
    I'm getting the error "user-defined type not defined"

  7. #7
    May be you are using MAC .. I am not sure
    On what line do you have the error?

  8. #8
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location
    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.

  9. #9
    May be you have to run the code I posted earlier first then run your code

  10. #10
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location
    I tried it is on the top of my code, is there another possible to run it before everything else ?

  11. #11
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,763
    Location
    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.
    Be as you wish to seem

  12. #12
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location
    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.

  13. #13
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,763
    Location
    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.
    Be as you wish to seem

  14. #14
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location
    I understood that but they'll only import the code, the workbook differs each time

  15. #15
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,763
    Location
    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.
    Be as you wish to seem

  16. #16
    VBAX Regular
    Joined
    Apr 2019
    Posts
    14
    Location
    and how does late binding work ?

  17. #17
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,763
    Location
    Declare any Word variables as Object - eg
    wdDok As Object
    - and declare any constants that you use from the Word object library.
    Be as you wish to seem

  18. #18
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Adding references with the code requires that "programmatic access to the VBA project" be enabled. By default it is turned off.
    Therefore vloneboy says:
    Quote Originally Posted by vloneboy View Post
    It doesn't work unfortunately
    Artik

  19. #19
    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.

  20. #20
    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.
    Last edited by Aussiebear; 07-18-2023 at 03:44 PM. Reason: Edited out the advertising spam within the post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •