Forum Discussion

PacoDeBenito's avatar
PacoDeBenito
Copper Contributor
Jun 27, 2023

Can't access Word objects from Excel VBA code

Hello!

I'm trying to write in a Word document from Excel VBA code, to place the data from am Excel table into a report. I added the "Microsoft Office 16.0 Object Library" to be able to work with Word objects from Excel, and in my code I defined variables as Word.Application, but when I run it, my program can't recognize this type.

In the "Tools >> References..." dialog box I can see that the location of this library is in "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE16\MSO.DLL", but when I access this folder "OFFICE16", to check what's inside, I can't find the archive MSO.DLL (I only see the "Office Setup Controller" folder, and the LICLUA.EXE archive).

There's this other thing... The folder "Program Files (x86)" appears in my system in Spanish, like "Archivos de Programa (x86)", and I don't know if this can also be important for the problem I have.

¿Can anyone help me to solve this? Thank you!

3 Replies

  • dlowell's avatar
    dlowell
    Copper Contributor

    PacoDeBenito I realize this is an older thread and hopefully you've already found a solution. I wanted to post for anyone else who comes across this thread having the same issue. I was struggling with this same thing. I had the "Microsoft Office 16.0 Object Library" selected in References but VBA was still not recognizing the Word.Application object. After searching through the list I found an available reference called "Microsoft Word 16.0 Object Library" and as soon as I activated that, the Word.Application object worked perfectly. I hope this helps! 

  • SnowMan55's avatar
    SnowMan55
    Bronze Contributor

    PacoDeBenito 

    "Microsoft Office 16.0 Object Library" does not contain the classes, etc., you are looking for, i.e., Word classes. Scroll further down in the References dialog to find "Microsoft Word 16.0 Object Library", and select it.

     

    Then open the Object Browser (under the VBA Editor's View menu); select Word from the upper dropdown list (which usually shows <All Libraries>) to see a top-level view of this library's classes. You can click on a class name to see its members, and click on a member name to see more info on it in the pane at the bottom (which has a draggable border, so you can make it taller/shorter).

     

     

    And yes, you can use the Object Browser to see what the Office Library makes available.

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    PacoDeBenito 

    The issue you are experiencing with accessing Word objects from Excel VBA code could be related to a few different factors. Here are some troubleshooting steps you can try:

    1. Confirming the correct reference: Ensure that you have added the correct reference to the Word Object Library in Excel VBA. While the library file may not be named "MSO.DLL" directly, it should still be available for selection. Look for "Microsoft Word x.x Object Library" in the list of available references (where "x.x" represents the version number).
    2. Reference path discrepancy: The file path you mentioned ("C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE16\MSO.DLL") indicates the 64-bit version of Office, which might not be the version installed on your computer. It is possible that you have the 32-bit version of Office installed, which would have a different file path. You can check the correct path by going to the "Tools >> References..." dialog box in Excel VBA, selecting the Word Object Library, and noting the "Location" field at the bottom of the dialog.
    3. Language-specific file names: The folder name "Archivos de Programa (x86)" instead of "Program Files (x86)" in your system should not cause any issues with referencing the Word Object Library. The folder names may be localized, but the libraries and references should still be accessible.
    4. Repair or reinstall Office: If you are unable to find the correct reference or the Word Object Library is missing, it's possible that your Office installation might be corrupted. In such cases, you can try repairing or reinstalling Office to ensure that all necessary files and libraries are in place. The texts and steps were created by the AI.

Resources