> I am trying to follow the advice given, but I think I have a syntax > problem: > > I coded the following, using the examples given, and looking at a > recorded macro that I made copying one sheet: > > excel = actxserver('excel.application'); > % open the excel file, full path need to be mentioned or else excel will > pick it from most recently opened files. > wkbk = excel.Workbooks.Open([pwd '\' DestFile]); > wksheet = wkbk.Worksheets.Item('Form1'); % Choose desired sheet > co=wksheet.Copy After:=Sheets(4); > wkbk.Save % save the changes > excel.Quit % close excel > > but of course the "After:=Sheets(4)" > does not work, it is matlab syntax error: I get > Unexpected MATLAB expression. > > If I code only > co=wksheet.Copy > I get: > ??? One or more output arguments not assigned during call to "Copy". > > 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
I never could find useful help on Excel VBA.
Trashing about, I arrived at something which might help:
excel = actxserver('excel.application'); % open the excel file, full path need to be mentioned or else excel will pick it from most recently opened files. wkbk = excel.Workbooks.Open('c:\tmp\in.xls'); %This file has a sheet called 'one' which has some formating wksheet = wkbk.Worksheets.Item('one'); % Choose desired sheet wksheet.Copy(wksheet); %this will create a sheet called one (2) and places it before one (not sure if this will be consistent) newSheet=wkbk.Worksheets.Item('one (2)'); %get a handle to this copied sheet newSheet.Name='CopiedSheet'; %rename it with a new name wkbk.Save % save the changes excel.Quit % close excel