Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Danny
Posts:
16
Registered:
9/17/09
|
|
Re: Copy a formatted sheet in Excel
Posted:
Mar 7, 2010 10:58 AM
|
|
> 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
|
|
|
|