I have a great Monte Carlo simulation macro for MS Project that I use all of the time. Since I upgraded my version of MS Office, it no longer works.
I got the macro from the following link: https://sourceforge.net/projects/montecarloprj/?source=typ_redirect
It generates an error (Compile error: User-defined type not defined) at the following line:
Sub SetupExcel(ByRef XlApp As Excel.Application, ByRef XlBook As Excel.Workbook)
Previously, to resolve this issue I needed to enable "Microsoft Excel 12.0 Object Library" in Tools-References in VBA. However, that option (or any Excel Object Library) is not available.
If you can't find the object library on the list, you can use the Browse button to add it to the list yourself. Find out where the excel.exe file is located and use the Browse... button in the References dialog box. Be sure to change the file type to Executable Files when adding the reference (lower-right corner of the Add Reference dialog box).
Related
I'm trying to create my first Excel Add-In for Excel 2010. Most of it is working, it's running from the ribbon buttons, but I'm having trouble addressing the Add-In's subroutines from my workbook's VBA code.
According to this answer on SO, it should be possible to simply use the syntax:
mySub
or
Call mySub
But this causes the error "Sub or Function not defined". I've only managed to run them this way:
Run "mySub"
or
Application.Run("myAddIn.xlam!mySub")
Is there a way to include the Add-In so I can address it the easy way?
The Add-In is already checked in the Tools->Add-Ins list, and has a unique name (CalcFunctions) which is different from its file name (CalculationFunctions.xlam). The Add-In file is on a different disk and I'm working on a server, but I don't expect that that matters.
(Posted on behalf of the OP).
Turns out I'm just dumb. I only set a reference to the Add-In in the regular Excel window. I assumed that was what people meant by Tools->References->Add-Ins (I use Excel in Dutch and there's no "Tools" menu). Anyway, the solution was setting a reference in that menu in the VBA editor window.
Here's how to add a reference in VBA:
ThisWorkbook.VBProject.References.AddFromFile refPath
With refPath being the full path to the file.
To be able to add references you need to have permission to edit the VBA project. You can enable this in excel settings->trust center->macro settings. If you're on a company pc it's likely the administrator has to set these settings for you.
I had made an Excel macro using some ActiveX control buttons. It runs perfectly on my old PC. Some days back I purchased a new PC and when I compiled it reflect following error:-
"Object Library invalid or contains references to objects definitions that could not be found."
Also when I run this macro in design mode through the ActiveX button, it creates a sample blank module by a new default name corresponding to that button.
I tried everything that is available on the web. I even removed .exd files, checked my .ocx files. etc.
Now I am clueless about what to do as same macro is running perfectly on my colleagues laptop and they also have same version of Excel even.
Screenshot of the error that I am getting when compiling the code.
Repro:
Start Excel and open VBE ALT+F11.
Find Tools and click References.
Scroll down til you find Microsoft Scripting Runtime and tick it.
Save the file as Addin.xlam in the default location which should be something like:
C:\Users\username\AppData\Roaming\Microsoft\AddIns
Close this Excel instance
Start a new instance and open VBE (you should now see the Addin.xlam as the second VBA Project available for the workbook. If you don't open the Developer tab then add-ins and tick the box next to the name to turn it on - save, close, open a new Excel instance)
Add a new standard Module
Open References and you should see only 4 ticked (default)
Scroll down and try to find Microsoft Scripting Dictionary - it ain't there!?
So, this basically means you can't add the reference to the new VBA Project (Book1) because your *.xlam is already using it
but
you can't cross-use the Scripting library because trying
Dim d as Dictionary
in that newly created Module1 fails as it doesn't recognise Dictionary object....
Is this somehow a known bug I have never realised or have I just completely overlooked something? Any workarounds?
The IDE keeps recently used references near the top of the list. Don't scroll down. It's right at the top. I'll admit. This threw me for a loop for a second too.
Hi I have an Excel 2003 application which has a listview embedded in the worksheet. It no longer works on Excel 2010.
I re-registered the ocx using regsvr32 C:\Windows\System32\MSCOMCTL.OCX as per advice.
This works for listviews on forms, but not for the worksheet.
Microsoft advises that Cannot insert object can be generated if the control is form specific and an attempt is made to add to the worksheet.
Can the listview be used in Excel 2010 on a worksheet
If so how?
Otherwise a rewrite will be required.
That happened to my Excel files using ActiveX or any sort of automation. The solution was confused at the beginning but the following link will help you.
Create a batch to remove cached control type libraries (extender files *.EXD) files from Windows
Opening each of the projects (Excel with macros)
Switch the file to design mode
Open VBA Code (Alt-F11) to edit any module and press from the main menu > Debug > Compile VBAProject
Switch back to Run Mode
Save and Close File
Reopen the file & test
Form Controls stop working after December 2014 Updates
I have a tried reading an embedded excel document in a word document. I followed the code specified at this blog article:
http://vbadud.blogspot.com/2010/08/how-to-read-excel-sheet-embedded-in.html
Dim oWB As Excel.Workbook
Dim oIShape As InlineShape
For Each oIShape In ActiveDocument.InlineShapes
If InStr(1, oIShape.OLEFormat.ProgID, "Excel") Then
oIShape.OLEFormat.Activate
Set oWB = oIShape.OLEFormat.Object
oWB.Sheets(1).Range("A1").Value = "ProdID"
End If
Next oIShape
It works fine but the Activate line causes the document to flicker on each excel document I read. I tried to remove the oIShape.OLEFormat.Activate code but it causes the next line to throw a "Runtime error '430' (class does not support Automation or does not support expect).
The question is there any other way to access embedded excel without calling the Activate method?
This is tricky! The short answer is, no. Not with an embedded Excel.
I did some experimentation and some research. Since I could not find any sources that specifically explained the behavior. this is somewhat a guess on my part. It appears that when you embed the Excel spreadsheet into your word document essentially Word stores a link of spreadsheet, which displays only the appearance because it needs to be interpreted with the Excel program. Until you actually active the shape, you cannot interact with it because that cannot be done with Word directly. This article alludes to the behavior, but doesn't explain it. Here's a quote:
If you edit the object in Word, click anywhere outside the object to return
to the destination file.
If you edit the object in the source program in a separate window,
click Exit on the File menu of the source program to return to the
destination file.
You may have noticed that even if you use. Application.ScreenUpdating = false it still does the flickering you mention. This is because you are using a different application when you access the shapes! Every time you active the shape, the object specific menus etc load.
A possible work around:
If instead of embedding Excel Spreadsheets via the insert menu, you can instead add a control. On my machine using Office 2003 the comparible one is: Microsoft Office Spreadsheet 11.0 This is technically a web control, but the methods and behavior are very comparable to an Excel workbook.
Using the control instead of the handy inserted object, with a slight variation of your code I was able to comment out your activate command and the code ran as expected. Specifically, I had to change these lines:
Dim oWB As Spreadsheet instead of Excel.Workbook.
If InStr(1, oIShape.OLEFormat.ProgID, "OWC11.Spreadsheet.11") Then instead of "Excel"
Basically you can decide... Activate your embedded object that requires Excel to interpret, or use a different control that doesn't require activation.