I know that there are millions of posts about this already but I cant seem to find one that mirrors my issue.
I am using VS2010 and want to automate excel and I'm trying to work through the example here.
MS Tutorial
The problem is when I go to add the reference as mentioned
3.Add a reference to the Microsoft Excel Object Library. To do this, follow these steps: •On the Project menu, click Add Reference.
•On the COM tab, locate Microsoft Excel Object Library, and click Select.
There is no such reference available.
Could someone please let me know if this is the right way to automate excel with VS2010.
If it is could someone please let me know why I dont have the COM option for excel.
Im wanting to write in VB.net but if someone has an example in C# that would be fine.
Kind Regards
Ash
I have tried implementing automation using the Microsoft.Office.Interop.Excel.Application dll but i get the following exception when I try to create the excel application.
This line generates the error.
EXL = New Microsoft.Office.Interop.Excel.Application()
This is the exception
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
If you have Office 2010 installed on your machine but still don't see it in the COM tab then there are reasonable odds that you have the 64-bit version of Office installed. Visual Studio is a 32-bit program, it cannot see the registry entries for 64-bit COM servers.
Workarounds are to use the primary interop assembly, it ought to be installed on your machine. Use the .NET tab and select Microsoft.Office.Interop.Excel. Next option is to import the type library directly. Use the Browse tab and navigate to c:\program files\microsoft office\office14 and select excel.exe. Set the Copy Local property of the added references to True to avoid having to deploy the PIA to the target machine.
Also be sure that your app can run as a 64-bit process. In vb.net that's selected with Project + Properties, Compile tab, scroll down, Advanced Compile Options, set Target CPU to "AnyCPU".
Related
Background
My office has used Office 2010 for quite some time, and I have written an application to generate some Excel files that we upload to a web site. Recently, our company decided to go with Office 365. So, on my development machine I had 2010 and 365 (whatever version that is), as well as Visual Studio 2017.
My company is assuredly going to require that all non-365 versions of office be removed, so today, I uninstalled 2010 to see what breaks.
The Issue
I fixed the references in the project to point to the correct objects now. I have a reference to Microsoft Excel 16.0 Object Library, and I ended up having to modify statements like
Dim ExApp AS Excel.Application= new Excel.Application
to
Dim ExApp AS Microsoft.Office.Interop.Excel.Application= new Microsoft.Office.Interop.Excel.Application
and now the code compiles with no errors. However, when I run it, I get the following error on the above statement:
System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID
{00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered
(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).'
I am not sure why.
Internet searches on that error are typically really old, and most describe trying to run the application on a machine where Office is not installed. I can't run it on my development machine in debug mode.
I just installed Visual Studio 2012 Ultimate and I am trying to create a managed code extension project for Excel 2010 (32 bit Office Professional Plus). I have tried using the .NET 4.0 template contained in VS Ultimate for an Excel 2010 workbook. When I create the project everything looks fine until I run it.
Excel opens and I get the error message "The customization assembly could not be found or could not be loaded. You can still edit and save the document. Contact your administrator or the author of this document for further assistance." The details section is blank.
I have tried everything I could think of to figure this out and I have run out of ideas. I removed all addins from Excel except for the VSTO Design-Time Adaptor for Excel. I removed all personal macros. I set every directory I could think of to "trusted" in Excel and lowered the security settings for all options to "enabled (not recommended)". I completely uninstalled Visual Studio and re-installed. There are no errors or warnings showing up in Visual Studio. I also checked to make sure ".NET Programmability Support" was installed for my copy of Microsoft Excel.
I would link my code but I haven't written anything. I can't even get the default template to load when I run the project. A few others at work have the same setup as me and VSTO runs fine for them using the same steps. I even had someone send me a working project but it gives me the same message when I try to run it.
Is there anything else I can check to see where the problem is occurring? I tried setting break points in the project but it is failing before it gets to any of them.
Thanks so much for your help.
I've run into the same problem with Visual Studio 2010.
I isolated the problem to an SSRS reporting link we were trying to run from the add-in. I removed all the reporting stuff (service reference, sub-dirs, etc.) - the add-in runs fine.
We just ran into this and discovered that a method had a system exception that was not handled. It was hard to track down but once the culprit method had an exception handler the customization finished loading properly.
I'm having some compatibility issues with a legacy VB5 program I inherited.
Specifically, the DBCombo control.
Where does this control come from? I think it might be from the Microsoft DAO Object Library but I want to make sure.
It is, well, was, an ActiveX control last seen in VB6. The DLL that supported it was named "DBList32.ocx". If you have a really old machine on which it was installed then you could copy that file from the c:\windows\system32 directory and register it with regsvr32.exe.
I can still add it to the VS2008 .NET toolbox by right-clicking it and selecting Choose Items, COM tab and ticking "Microsoft DBCombo Control" (got VB6 installed on the machine). Didn't actually try to use it, odds are low after the Windows 7 SP1 update for ADO that broke backwards compatibility.
I have a Visual Basic DLL, I used it in a Windows User Control Application. It works fine, but when I HOST this Windows User Control in another Windows Forms application, it gives me the following error.
An error occurred creating the form. See Exception.InnerException for details. The error is: Creating an instance of the COM component with CLSID {66DF4F1A-E3E2-43D3-92BC-D56E9DDCB8AC} from the IClassFactory failed due to the following error: 800a005b.
When I run the User Control it works fine with me, ONLY when I host it in another Windows application this error occurs.
I'm using Visual Studio 2008 & Windows Server 2003
when I add the User Control, the DLL path is "C:\Documents and Settings\USERNAME\My Documents\Visual Studio 2008\Projects\HMS_WF4\HMS_WF4\obj\Release\Interop.DLLNAME.dll"
Notes. it's in Release, but when I compile the application it puts the output in the Debug folder. Even if I select the Release folder for debugging and compilation, when the application is run, it searches for the DLL in the Release folder, but it's in the Debug folder.
I get it....
When I host the User Control in a Windows Forms application, it initialize objects from the User Control objects in Form1.Designer.vb. Like Me.FrmTransactions31.TransHdr = CTransHdrClass2.
I just replaced CTransHdrClass2 with Nothing
Thanks for all.
I'm trying to diagnose why my Outlook plugin written in C#/VSTO 3.0/VS 2008 doesn't load after being installed.
The plugin works awesomely on my development machine, which has Visual Studio 2008 installed. I can't expect all my users to have all the prerequisites though so I went through these steps to write an installer:
http://msdn.microsoft.com/en-us/library/cc563937(loband).aspx
I installed the add-in on a fresh Windows XP SP 2 machine with a fresh install of Outlook 2007. It installs all the prereqs ok (.NET 3.5, VSTO 3.0 runtime, Windows Installer 3.1, 2007 PIAs). Outlook starts but the add-in isn't run. If I go to the Add-ins tab in the Trust Center, I see my add-in in the "Inactive Application Add-ins" section with the message "Not loaded. A runtime error occurred during the loading of the COM Add-in.".
Not sure how to find the specific error so I can fix it.
The reg keys look ok. Under HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\BlahAddin I see Description, FriendlyName, LoadBehavior (set to 3 until it fails after which if becomes set to 2), and Manifest.
Tried the VSTO_SUPPRESSDISPLAYALERTS environment variable trick and then launched Outlook from the command line but no output came out.
I have remote debugging more or less working but I'm not sure what to look for. I don't see my DLL loaded when I attach to Outlook, but then again maybe managed DLLs don't show up the same way in VS.
Any other ideas on next steps I could follow to produce a specific error I can diagnose?
Solved my problem after weeks of pain. The "Manifest" reg key was getting corrupted to some junk value during the setup build. It was a known Visual Studio bug that supposedly got fixed in Visual Studio 2008 SP 1, but apparently wasn't for me. Renaming the project name to be different from the plugin name fixed the problem. Random, huh?
Make sure you have try-catch handlers at the top level of all methods called by Outlook and log any exceptions you are unable to handle in some way. Focus your troubleshooting on methods like the Startup method and other methods called during initialization.
You probably want to debug this using the remote debugger. Share out the MSVCMON.EXE folder from your developer machine (in your Visual Studio folders in Program Files) on your test machine (share it with a UNC path), and launch Outlook under the debugger trapping (.NET) exceptions in your modules and putting breakpoints in your methods.
If you need to clean your test computer each time before you install your solution, you should probably run XP under a Virtual PC 2007 VM (free download) and switch to a differencing HD after setting up everything but your plugin to snapshot your pre-installed state once so you don't have to keep uninstalling/reinstalling as you make changes to your program to fix bugs.
Are you installing Debug builds or Release builds? Perhaps one flavor has different requirements. Just guessing.
-Mike [MSFT Office Dev]
On your machine, when you run the addin from Visual Studio, it should create a registry key in HKEY_CURRENT_USER\Software\Microsoft\VSTO\Security\Inclusion{SomeGuid}. Make sure that these registry settings are also being deployed with your addin. They are the ones that allow your code to be trusted.