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).
"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 ) 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).
@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!
A friend of mine is missing the Microsoft Office XX.0 Object Library. He has office 2016 installed. He is using a code that I generated to export a bill of materials from Inventor to excel. A reference to the Microsoft Office XX.0 Object Library is required. This object Library is not present in the References window (VBA>Tools>References). Is there a way to download another/find in his directory?. Would I be able to give him a copy of my object library? If so, what would be the filename for the library?
I figured it out though. The main issue I was having was determining the location and name of the dll file. For me, the object library was only missing from the references window while using vba editor in Inventor. When I open up excel and pull up its vba window, the object library was not missing from the list.
So I clicked on the Microsoft Office 16.0 Object Library from the excel vba references window and it shows the full file path. But it cuts off before the end. I had a nightmare with this and Microsoft help chat/calls.
The next morning I opened Visual Studio 2015 and opened a Visual Basic > Windows > Classic Desktop > Console Application. From the Solution Explorer, I right clicked References > Add Reference. A window came up with an extensive list of object libraries. I found the Microsoft Office 16.0 Object Library that I was looking for, and when I put the cursor over the listed object library, it displayed the full path and file name uncut and uncensored.
Finally, I went back into the inventor vba window > Tools > References. I then clicked browse in the new window and found my dll file. It was named Office once it was in the References window. I closed the references window and reopened it to find the Microsoft Office 16.0 Object Library just as it should be. All of this just so I can create File Dialogs!
Anyways, I can't imagine I am the only one in the world who had or is having this issue with an object library. For Office 2016, here is the full file path, which I imagine will be the same for any user because I believe it is a default directory:
If anyone is having a similar issue with an object library and they know it is on their computer somewhere, employ the aforementioned method using Visual Studio 2015; Community Edition should work fine.
However, I'd like to point out that some functions change between versions of Office. That might create some issues for you if you're not anticipating those changes. (Speaking from personal experience on this.)
In Re^2: Finding out Excel 'variables', I reproduced ActiveState's code for listing Excel's constants and values. I think it would be relatively simple to adapt this to other libraries. I would therefore start thinking along the following lines:
If any constant does in fact vary, how would I know which to use? If you have or can get (not all that difficult in Excel) the version number, you might try creating your own hash of hashes containing all the constants, so that you would have a key, say xlVisible, and a hashref giving you the constant values for each version of the library that you have available. This means a large data structure, so my next thought would be to isolate the constants that are actually used. Again, if they are all the same, just use the latest version.
Another option is not to use constants at all, but magic numbers. This isn't ideal, but sometimes it's the least work, especially if the constant isn't in the library. So, when writing Perl to control Excel, I frequently write something like:
I forget how I figured out that I needed to put in the exact version number (11.0, 12.0, or 14.0), but that is the only way I have been able to get this to work. I tried to figure out a way to select the right version in a BEGIN-END block, but I lack the perlMonkishness to get that going.
I can live with one of two solutions (either modify the script for the specific host version of Office -- yuck); or the way it is now (looks ugly as sin, but seems to work; and if multiple versions of office exist, I'll take my chances.
Private Sub CreateDialog() ' set reference to Microsoft Office 12.0 Object Library ' set reference to Microsoft Excel 12.0 Object Library Dim objExcel As Excel.Application Dim dlg As FileDialog Set objExcel = New Excel.Application Set dlg = objExcel.FileDialog(msoFileDialogFolderPicker) dlg.Show If dlg.SelectedItems.Count = 0 Then GoTo exit_now lblStatic.Caption = dlg.SelectedItems(1) exit_now: Set objExcel = Nothing Set dlg = NothingEnd Sub
In everything I did, I showed you that by this kind of hard work we must help the weak, remembering the words the Lord Jesus himself said: 'It is more blessed to give than to receive.'--Acts 20:35
:cool:
On the contrary of 'Early Binding', the 'Late Binding' allows you to use your application even on computers that do not have the same version of Excel that you used for the development, because it is linked to it.
The bad news is that with the 'Late Binding' the VB6 intellisense does not work, so objects, properties and methods are no longer accessible by typing a period (.) after the name of the objExcelApp. Although the context-sensitive help does not work anymore (Office 2007 and later.)
The good news is that there is a way, little known, to use both techniques Early Binding and Late Binding at the same time, or in the IDE using the Early Binding, but compiled will be used Late Binding.
Well, I know that in VB6 you have the CommonDialog control, that does pretty well. It offers just about all of the same features as the FileDialog control. Take a look at this and see if this will work. If not, you could design your own using various controls from VB6 if you needed a more custom dialog.
There are API calls that will give a folder viewer but these are quite priimitive compared with the office dialog utility which, as I said, I can get to work from VBA but not from VB6. Hence the post.
But my real topic was I can set references to Word, Excel and Access object libraries in VB6 and use their facilities but setting a reference to Microsoft Office 12.0 Object Library shows me the all the objects.
e59dfda104