View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
BrassicaNigra BrassicaNigra is offline
external usenet poster
 
Posts: 2
Default Copy range values in C#

Thank you so much. This resolved my issue. I did use

Microsoft.Office.Interop.Excel.XlPasteType.xlPaste Values

instead of

Microsoft.Office.Interop.Excel.XlPasteType.xlPaste Formulas

because all I want to copy is the current value in the cell.

""Jie Wang [MSFT]"" wrote:

Hello Dale,

The PasteSpecial approach is right. Actually you are very close to the
solution now!

First, the Copy method can take zero arguments in VB because it supports
optional parameters, however this is not the story in C#. So we'll have to
pass in something. In this case, it would be Type.Missing.

And we need to specify correct parameters to the PasteSpecial method to
make it work.

I made a little bit changes to your code and please let me know if it works.

/* Begin code snippet */
String strTopSourceCell = "A2", strBottomSourceCell = "A46";
String strTopDestinationCell = "F16", strBottomDestinationCell = "F60";

Excel.Worksheet activeWorksheet =
(Excel.Worksheet)Globals.ThisAddIn.Application.Act iveSheet;

Excel.Range exrSource = activeWorksheet.get_Range(strTopSourceCell,
strBottomSourceCell);

Excel.Range exrDestination =
activeWorksheet.get_Range(strTopDestinationCell, strBottomDestinationCell);

exrSource.Copy(Type.Missing);
exrDestination.PasteSpecial(Microsoft.Office.Inter op.Excel.XlPasteType.xlPas
teFormulas,

Microsoft.Office.Interop.Excel.XlPasteSpecialOpera tion.xlPasteSpecialOperati
onNone,
false,
false);
/* End code snippet */

Regards,

Jie Wang , remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.