.NET Interop Copy all cells from Worksheet to Clipboard
No idea about the .Net stuff, but if you receive all those errors for a copy
statement, you have some work to do.
Check the documentation for the Copy method and see what it expects as a
destination; a string, range or what. With ( ) or without.
NickHK
"andalmeida" wrote in message
...
thanks, so i tried, but failed:
Excel.Range range = oExcelApp.Cells;
range.Copy("A1");
and got same exception:
"Copy method of Range class failed"
" at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)\r\n at Excel.Range.Copy(Object Destination)\r\n at
xlsconcat.Form1.button2_Click(Object sender, EventArgs e) in
C:\\Anderson\\xlsconcat\\Form1.cs:line 53\r\n at
System.Windows.Forms.Control.OnClick(EventArgs e)\r\n at
System.Windows.Forms.Button.OnClick(EventArgs e)\r\n at
System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)\r\n at
System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button,
Int32
clicks)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at
System.Windows.Forms.ButtonBase.WndProc(Message& m)\r\n at
System.Windows.Forms.Button.WndProc(Message& m)\r\n at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)\r\n
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)\r\n
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)\r\n at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)\r\n
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.Unsaf
eNativeMethods.IMsoComponentManager.FPushMessageLo op(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)\r\n at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason,
ApplicationContext context)\r\n at
System.Windows.Forms.Application.Run(Form mainForm)\r\n at
xlsconcat.Program.Main() in C:\\Anderson\\xlsconcat\\Program.cs:line 17"
"NickHK" wrote:
If would guess it is because you are not specifying a valid range. In
VBA
Dim CopyRange As Range
Set CopyRange = Worksheets(1).Cells
CopyRange.Copy Worksheets(2).Range("A1")
NickHK
"andalmeida" wrote in message
...
Hey,
Does anyone know how to copy all cell contents from a Sheet to the
clipboard?
I tried:
Excel.ApplicationClass oExcelApp;
oExcelApp = new Excel.ApplicationClass();
oExcelApp.DisplayAlerts = false;
oExcelApp.Workbooks.Open(fileName.ToString(),
System.Reflection.Missing.Value, false,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value, System.Reflection.Missing.Value,
true,
System.Reflection.Missing.Value, System.Reflection.Missing.Value,
System.Reflection.Missing.Value, false,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value, System.Reflection.Missing.Value,
System.Reflection.Missing.Value);
Excel.Range range = oExcelApp.Cells;
range.Select();
object dest = new object();
range.Copy(dest); <- i got a nice Exception here :-(
Thanks Dudes
|