Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

Topic: Copy a formatted sheet in Excel
Replies: 9   Last Post: Jul 11, 2013 6:03 AM

Advanced Search

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

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
end

%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"
Sheets.Item('1').Move(Sheets.Item('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]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.