I have googled this problem and have not been able to come up with a solution. This code works if the file is saved as an .xls but not .xlsm. I am using Office 2013 (32-bit).
I have written a C# class library that is COM exposed. The excel workbook instantiates an object and passes in a reference to the current workbook. The object then calls the excel object and updates Label1's caption on the first sheet.
I have opened up all trust center settings (it works with .xls files) and the .xlsm file is not protected in anyway.
I have tried a couple different methods of updating the caption, I have made sure I am using OLEObjects
- but it still throws a Unable to get the Object property of the OLEObject class
.
//Method 1
OLEObject label = this._currentBook.ActiveSheet.OLEObjects(1);
label.Object.Caption = "New text";
//
//Method 2
int index = -1;
foreach (OLEObject obj in this._currentBook.ActiveSheet.OLEObjects)
{
if (obj.Name.ToUpper() == "LABEL1")
{
index = obj.Index;
}
}
if (index >= 0)
this._currentBook.ActiveSheet.OLEObjects(1).Object.Caption = "Some text";
//
//Method 3
this._currentBook.ActiveSheet.OleObjects("Label1").Object.Caption = "Different text";
This code has to take place in the class library as that is the business rules I need to comply with. The excel vba merely instantiates my class object and the managed code does the rest.
The solution is to delete all the .exd files from your %APPDATA% and %TEMP% because...
Thanks to yay_excel for assisting me. Here is the page that helped me out:
http://www.excelforum.com/excel-programming-vba-macros/1060133-run-time-error-1004-on-certain-machines.html
Which in turn points to this MSDN Knowledge Base article: MSDN