Copying and pasting as value

324 views
Skip to first unread message

fah...@cbinsights.com

unread,
Aug 2, 2013, 10:49:19 AM8/2/13
to exce...@googlegroups.com
Does anyone have example code on how to copy and paste an entire worksheet (or even workbook) as value?

Basically, I want to provide a button to the user that will take all the formula results on the sheet and "make them static" such that the formulas are never recalculated (basically what copy/paste as value does).

Thanks!

Patrick O'Beirne

unread,
Aug 2, 2013, 12:40:27 PM8/2/13
to exce...@googlegroups.com
with worksheets("somename")
.usedrange.copy
.cells(1,1).pastespecial Paste:=PasteValuesAndNumberFormats
end with
> --
> You received this message because you are subscribed to the Google
> Groups "Excel-DNA" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to exceldna+u...@googlegroups.com.
> To post to this group, send email to exce...@googlegroups.com.
> Visit this group at http://groups.google.com/group/exceldna.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Farhan Ahmed

unread,
Aug 2, 2013, 3:26:40 PM8/2/13
to exce...@googlegroups.com
That works wonderfully.

I just made a slight change:

.usedrange.cells(1,1).pastespecial Paste:=PasteValuesAndNumberFormats

Otherwise it moves the content if the content doesn't start at (1,1).

Also, I'm writing in C#, so here's the relevant code (for future searchers):

                Excel.Application app = (Excel.Application)ExcelDnaUtil.Application;
                dynamic sheet = app.ActiveWorkbook.ActiveSheet;
                sheet.usedrange.copy();
                sheet.usedrange.cells(1, 1).pastespecial(Excel.XlPasteType.xlPasteValuesAndNumberFormats);

Thanks!


On Fri, Aug 2, 2013 at 12:40 PM, Patrick O'Beirne <obeir...@gmail.com> wrote:
with worksheets("somename")
    .usedrange.copy
    .cells(1,1).pastespecial Paste:=PasteValuesAndNumberFormats
end with


On 02/08/2013 15:49, fah...@cbinsights.com wrote:
Does anyone have example code on how to copy and paste an entire worksheet (or even workbook) as value?

Basically, I want to provide a button to the user that will take all the formula results on the sheet and "make them static" such that the formulas are never recalculated (basically what copy/paste as value does).

Thanks!
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+unsubscribe@googlegroups.com.

To post to this group, send email to exce...@googlegroups.com.
Visit this group at http://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+unsubscribe@googlegroups.com.

To post to this group, send email to exce...@googlegroups.com.
Visit this group at http://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/groups/opt_out.





--
Farhan Ahmed
Product Manager | CB Insights
Reply all
Reply to author
Forward
0 new messages