The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Copy a formatted sheet in Excel
Replies: 10   Last Post: Jun 2, 2015 2:55 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 16
Registered: 9/17/09
Re: Copy a formatted sheet in Excel
Posted: Mar 7, 2010 10:58 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> How do I specify the argument "After" that says after which sheet I have to copy? there is here probably some special syntax that I am missing.
> Any help will be very appreciated!
> Best regards
> Claudio

First off, I have found this thread very helpful, thank you!

I also wanted to try to copy a sheet after the active sheet, but I could not find the right syntax for the copy command either. Instead I found a solution which let me re-order the sheets afterwards. Maybe this will be helpful to you too:

excel = actxserver('excel.application');
ExcelFile = 'filename';
%open the excel file
wkbk = excel.Workbooks.Open(ExcelFile); %This file has a sheet named "1" which has some formating

wksheet = wkbk.Worksheets.Item('1'); % Choose desired sheet

for n = 2:5
%make a copy of the template sheet
wksheet.Copy(wksheet); %this will create a sheet called "1 (2)" and places it before "1"
newSheet=wkbk.Worksheets.Item('1 (2)'); %get a handle to this copied sheet
newSheet.Name=num2str(n); %rename it with a new name

%In Excel this results in five sheets, in order named: 2 3 4 5 1, but I want the order: 1 2 3 4 5

% Get the list of sheets in the workbook
Sheets = wkbk.Sheets;
% Moves Sheet "1" to before sheet "2"

Best Regards,
Danny Sale

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.