PasteSpecial method of Range class failed

Add-in Express™ Support Service
That's what is more important than anything else

PasteSpecial method of Range class failed
I have code that works OK in Delphi 2005 and old Add-In, but fails with Delphi XE3 and latest Add-In 
rkongs


Guest


Hello,

I have problem with Delphi XE3 and new Add-In library. I have old add-in made in Delphi 2005 and old add-in version (probably 2.6, build 260), there is piece of code, where I copy range form one sheet to another, like this:

var
...
r1, r2: OleVariant;
...
begin

...
lSrcSheet:= ASrcWorkbook.Worksheets['Report'];
r1:= lSrcSheet.Range[lCellSrcStart,lCellSrcEnd];
r2:= ADstWorksheet.Range[lCellDstStart,lCellDstStart];

r1.Copy;
r2.PasteSpecial(xlPasteValues); //it fails here

...

end;

The same code works fine in D2005 but fails with the new add in and Delphi XE3. In both cases I run add-in with Excel 2003. I did not make any big changes in the code, when transferring to XE3, only minor syntax things.

I tried to google, and there are lots of explanatins for PasteSpecial to fail, but the thing is that in both cases we work towards same Excel COM object and theoretically it should retrieve same method call and do same things. So may be there are differences in Delphi XE3 to call com objects.

I would understand that something is globally wrong if all calls to excel failed, but there are lots of them (except for PasteSpecial) and it works.

I wonder did you ever experience anything similar, or may be have ideas how to solve this?

Best Regards
Robert Kongs
Posted 18 Jan, 2013 04:38:57 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hello Robert,

You can try to use late binding. What exception are you getting?


Andrei Smolin
Add-in Express Team Leader
Posted 18 Jan, 2013 04:56:29 Top
rkongs


Guest


I am getting EOleException - "Project EXCEL.EXE raised exception class EOLEexception with message 'PasteSpecial method of Range class failed'.

regarding the late binding I think I am using it. I get Excel into OleVariant from TAddInModule.HostApp and then refer to it (and other objects, like workbook, sheet, range, etc.) without type library.

Robert
Posted 18 Jan, 2013 05:10:19 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Do you paste to the active worksheet? Is the target worksheet visible? Please make sure that you are not editing a cell at this moment. Also, please check whether this code produces the same behavior when run in the event handler of a test button.

If you provide a sample project, we could test it in D2005 and in XE3.


Andrei Smolin
Add-in Express Team Leader
Posted 18 Jan, 2013 05:32:19 Top
rkongs


Guest


I have sent test project through the support form. Just a note - when dll compiled by D2005 is copied to the Win7 machine with Delphi XE3 it works OK. But I guess you will see it yourself, have a nice weekend :)
Posted 18 Jan, 2013 10:51:44 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hello Robert,

Thank you for sending the project. We've reproduced the issue. It works if you use (ExcelRange(IDispatch(r2))).PasteSpecial(xlPasteValues, xlNone, false, false). We don't know why it doesn't work the other way.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jan, 2013 10:28:26 Top
rkongs


Guest


Hello Andrei,

Thanks a lot! Fantastic, I was preparing to set formatting manually :)
Looks like some Delphi compiler problem.

Regards,
Robert
Posted 22 Jan, 2013 02:17:15 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 22 Jan, 2013 04:14:55 Top