I have a problem with running a VBA in a Excel spreadsheet on a MacOS (Sierra). On Windows everything works like expected. I always get the "Compile error in hidden module: Interpolation ...
I tried to remove the whole content of the module and this is the leftover:
Function interpolate(x As Double, ran As Range) As String
interpolate1 = 1
interpolate = interpolate1
End Function
The VBA code is password protected and I don't use any ActiveX controls.
The references I use are as follows:
Visual Basic For Applications
Microsoft Excel 16.0 Object Library
OLE Automation
Microsoft Office 16.0 Object Library
Microsoft Forms 2.0 Object Library
RefEdit Control
If anyone has any suggestions on how to go about this problem, that would be great.
Thanks,
Tro
The RefEdit reference was missing on MacOS. I removed it and now it seems to work.
Related
I built a excel macro using the "Microsoft Outlook 15.0 Object Library" reference, but when I send the file to other people they get this error: "Can’t find project or library".
This file will be used by a lot of people, so I have to add it from VBA Code.
I'm using this code that runs when you open the excel file, which is returning the following error: "Error in loading DLL"
Private Sub Workbook_Open()
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (x86)\Microsoft Office\Office15\MSOUTL.OLB\"
End Sub
Do you have any idea why this is happening?
Thanks
If you still want to keep the early binding you could use the GUID in order to add the libray, i.e.
Sub AddOL_Ref()
Application.VBE.ActiveVBProject.REFERENCES. _
AddFromGuid "{00062FFF-0000-0000-C000-000000000046}", 1, 0
End Sub
Advantage of using the GUID is that it is constant and does not change with the version of the program.
Here one finds an extened discussion on dis/advantages of early resp. late binding.
You will have to remove the references & use late binding
or you can also try this. Send your code to one of the user having 2010MS.
Goto VBA > Tools > References
Check for any missing references. You may have Microsoft Outlook 15.0 Object Library showing as missing. Un-check this, browse down and select Microsoft Outlook 14.0 Object Library.
Ultimately I want to build a MS Project file using early binding from VBA behind XLS or MPP.
In order to do that, it is my understanding that you should go to Tools--> References and select the Microsoft Project XX.X Object Library.
Unfortunately, it wasn't in the list.
The References pop-up allows you to browse, and select the reference library manually. Great! But, where do I look, and what file do I select to import this reference?
Assuming you are looking in Excel VBA References's list, it should just show up. Here's mine:
Note that I see it as Microsoft Office Project XX.X Object Library, you asked about Microsoft Project XX.X Object Library (lacking Office).
My environment is Win10; both Excel 2016 32-bit and Project 2016 32-bit are installed.
Perhaps try re-installing your Office components? Perhaps try making sure you have both the same bit architecture (32 or 64).
I've written a piece of kit on Excel 2016 that uses a combination of formula and vba macros.
Basically some of the people that will be using this may be using an older version of Excel (2013 or 2010). When testing out whether the file will run on 2013 the Microsoft Powerpoint 16.0 library was missing and some of the code would not run.
The only fix was to add the Microsoft PowerPoint 15.0 library and then it seemed to work.
Is there any way to add the libraries automatically when I send this file to other people, or add the 15.0, 14.0 and 13.0 library's in my copy so that this is not an issue for other users?
[EDIT] From further reading it appears that older versions of excel use different libraries and it doesn't look like you can "pick and choose" whether to use 16.0, 15.0 etc. (Please correct me if I'm wrong). Apparently there is something called "Early/Late Binding" which might help me out, I assume this is referencing within my actual VBA code so if that is a viable solution any more information would be appreciated.
You have two options.
Develop on the lowest common denominating Office version (references will automatically "upgrade" on newer versions)
Change your code from early binding (using a reference to the library) to late binding (using generic Object declarations for everything related to PPT, replacing all PPT constants with their associated values). You then get a reference to Powerpoint using the CreatObject or GetObject function.
In an Excel 2003 VBA project I am using controls from MSCOMCTL.OCX. That is the VBA project has a reference to System32\MSCOMCTL.OCX.
When I open that project in Excel 2003 on my 64-bit Windows 7 system, Excel automatically changes the reference to SysWOW64\MSCOMCTL.OCX (which is the correct location).
However, when I send that project to my client who is using 32-bit Windows XP, the project complains during opening because SysWOW64\MSCOMCTL.OCX does not exist on his system.
Here are the (unsatisfactory) solutions I came up with so far:
Instruct the client to manually change the reference back to the correct location on his system (System32\MSCOMCTL.OCX).
This does not really work for the following reasons:
When Excel 2003 32-bit opens the sheet and it cannot find the reference to MSCOMCTL, it removes all the controls that came from the library (e. g. TreeCtrl) from the forms :-(
Client is struggling with the procedure and it is quite cumbersome for him.
Automatically correct the reference using VBA's VBProject.References.AddFromFile/AddFromGuid.
Same problem as above: When compilation of VBA during opening of workbook fails, Excel will remove all controls that it could not find from the forms.
Automatically add the reference (as in 2.) and use dynamic binding to add all the relevant controls during runtime.
This could actually work, however currently I am struggling with binding the event handlers to the controls (but that will be separate question ;-)
Approaches 1. and 2. do not really solve anything and solution 3 is a lot of work.
Any ideas would be greatly appreciated.
What if you automatically turned the reference off when the workbook closed? that way the reference wouldn't be 'broken' when the workbook is opened, and all your control should still be good.
i.e. :
Private Sub Workbook_Open()
'use environ variable for folder locs
If os = "64bit" Then
Me.VBProject.References.AddFromFile ("C:\WINDOWS\SysWOW64\MSCOMCTL.OCX")
Else
Me.VBProject.References.AddFromFile ("C:\WINDOWS\system32\MSCOMCTL.OCX")
End If
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
For Each ref In Me.VBProject.References
If ref.Name = "MSComctlLib" Then
Me.VBProject.References.Remove ref
End If
Next ref
End Sub
I did a quick test with the ADODB dll and it seemed to work,but I am not sure how you're using that DLL specifically; let me know if that works, though! Sure a lot better than option 3!
I am trying to import xml data into excel..
So the first line of the code is
Dim XMLDOC As MSXML2.DOMDocument
and this gives an error "user defined type not defined"
Inside the VBE, Go to Tools -> References, then Select Microsoft XML, v6.0 (or whatever your latest is. This will give you access to the XML Object Library.
Updated with fancy pic!
I had DOMDocument defined which needed Microsoft XML, v3.0 but I had Microsoft XML, v6.0 selected in references which caused the below error
"user defined type not defined".
The solution
The solution was to either change DOMDocument to DOMDocument60 (60 uses ver 6.0) or use the Microsoft XML, v3.0 reference with DomDocument.
Just a quick note, if anyone is using a different version, such as Microsoft XML, v4.0, then DOMDocument40 should be used. This is because the number at the end of the DOMDocument is specific to the version of the library being used.
I work with a VBA Excel Macro that someone else wrote and I was tasked with fixing it after recently upgrading from Windows 7 / Office 2010 to Windows 10 / Office 2016. I started to receive the same "user defined type not defined" compile error. My previous install also had MS XML v6.0 but apparently you have to specifically point to this version in your code on Windows 10 and/or Office 2016 (I wasn't able to confirm which upgrade caused the issue). I was able to resolve the issue by doing a Find/Replace on the following:
"DOMDocument" to "MSXML2.DOMDocument60"
"XMLHTTP" to "MSXML2.XMLHTTP60"
I am using Microsoft Windows 10 & Office 2016.
Using Microsoft XML 6.0 does not fix the problem.
Selecting Microsoft XML 3.0 fixed the compilation error
I had the 3rd and 6th versions installed, and the project uses the 4th one. I installed the 4th version from https://www.microsoft.com/en-us/download/details.aspx?id=15697 and this solved the problem.