Copy and Paste?

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

Copy and Paste?
 
Kirk Boyd




Posts: 11
Joined: 2008-10-17
I have not figured out how to copy and paste from the current selection in Excel. Does anyone know how? Also, I noticed that TAdxExcelAppEvents does not include OnUndo event. Is there a way to point to this event?

Thanks,
Kirk Boyd
Posted 08 Dec, 2008 08:30:46 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Kirk,

I have not figured out how to copy and paste from the current selection in Excel. Does anyone know how?


Please see the Copy and Paste/PasteSpecial methods of the Range interface.

Also, I noticed that TAdxExcelAppEvents does not include OnUndo event. Is there a way to point to this event?


There is no such event in the Excel Object Model. But the OnUndo method exists.

Posted 08 Dec, 2008 09:20:24 Top
Kirk Boyd




Posts: 11
Joined: 2008-10-17
The selection is Shapes not cells. I do not see Copy/Paste methods in the ShapeRange interface.
Posted 08 Dec, 2008 15:14:54 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Kirk,

You can copy and paste each shape, one by one. Please see the code below:


var
  i: Integer;
  SrcWorksheet: _Worksheet;
  DstWorksheet: _Worksheet;
begin
  if ExcelApp.Workbooks.Count 
>
 0 then begin
    try
      SrcWorksheet := ExcelApp.ActiveWorkbook.Worksheets.Item['Sheet1'] as _Worksheet;
      DstWorksheet := ExcelApp.ActiveWorkbook.Worksheets.Item['Sheet2'] as _Worksheet;
    except
      // not found
      Exit;
    end;
    try
      for i := 1 to SrcWorksheet.Shapes.Count do begin
        SrcWorksheet.Shapes.Item(i).Copy();
        DstWorksheet.Paste(EmptyParam, EmptyParam, adxLCID);
      end;
      DstWorksheet.Activate(adxLCID);
    finally
      SrcWorksheet := nil;
      DstWorksheet := nil;
    end;
  end;
end;


Posted 09 Dec, 2008 08:51:08 Top
Mark K


Guest


Hi Dmitry,

There is no such event in the Excel Object Model. But the OnUndo method exists.


Can you let me know how you use this method? The procedure name it wants is a VBA macro. How do you make it call a Delphi function?

Thanks

Mark
Posted 28 Dec, 2008 00:49:58 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Mark,

Yes, you are right, the OnUndo method requires a macro name. You can call a Delphi method from within a macro using the COMAddins collection and the Object property of COMAddin interface. Please see the VBA macro below:

Public Sub TestUndo()

Application.COMAddIns.Item("ProgID_of_your_add_in").Object.your_method

End Sub


You can use the Type Library editor in Delphi IDE to add a new method to default interface of your add-in.


Posted 30 Dec, 2008 10:58:32 Top
Mark K


Guest


Thanks Dmitry,

I am trying to get the Undo functionality to work. There is code out there that uses an OnUndo macro but I am trying to not add a macro if possible as some people have macros turned off.

Is there anyway to set a cell's contents without it being treated as a macro and therefore wiping out the Undo stack? Are there any other ways to get around it or get undo to work?

Thanks for responding to my original query when I know you are on holidays :-)

Cheers

Mark
Posted 01 Jan, 2009 05:05:56 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Mark,

I am afraid nothing can be done here. As far as I know, the Excel Object Model doesn't provide any possibility except for using macros.


Posted 03 Jan, 2009 12:18:08 Top