"Quy" wrote in message <kht8tf$381$1@newscl01ah.mathworks.com>...
> "james bejon" wrote in message <kgrc3f$f05$1@newscl01ah.mathworks.com>...
> > Hard to say what the problem is without knowing more about the specifics of your book.
> >
> > One idea might be to try that line of code on a completely fresh workbook. If it works, then the problem's probably to do with the particular book--perhaps some of the rows are already grouped, perhaps the sheet's protected, etc.
>
> Here is the complete code:
>
> Excel1 = actxserver('Excel.Application');
> WB = Excel1.Workbooks.Add;
> WS = WB.Worksheets;
> Sheets = Excel1.ActiveWorkBook.Sheets;
> Excel1.Visible = 1;
> while WS.Count < 7
> WS.Add([],WS.Item(WS.Count));
> end
> sheet1 = get(Sheets, 'Item', 1);
> sheet1.Activate;
> eRangeSTOP.NumberFormat = '@';
>
> STOP_TBL_idx = find(~cellfun('isempty',regexp(STOPCompareDiff,'_STOP_TBL')));
> for ii = 1:length(STOP_TBL_idx)-1
> set(sheet1.Range([num2str(STOP_TBL_idx(ii)+1) ':' num2str(STOP_TBL_idx(ii+1)-2)]),'Group',1)
> end
Found a solution; not sure if it is the best one though (no need to set(), just use Range.Group
for ii = 1:length(STOP_TBL_idx)-1
TempRange = Excel1.Activesheet.get('Range', [num2str(STOP_TBL_idx(ii)+1) ':' num2str(STOP_TBL_idx(ii+1)-2)]);
TempRange.Group
end
> "james bejon" wrote in message <kgrc3f$f05$1@newscl01ah.mathworks.com>...
> > Hard to say what the problem is without knowing more about the specifics of your book.
> >
> > One idea might be to try that line of code on a completely fresh workbook. If it works, then the problem's probably to do with the particular book--perhaps some of the rows are already grouped, perhaps the sheet's protected, etc.
>
> Here is the complete code:
>
> Excel1 = actxserver('Excel.Application');
> WB = Excel1.Workbooks.Add;
> WS = WB.Worksheets;
> Sheets = Excel1.ActiveWorkBook.Sheets;
> Excel1.Visible = 1;
> while WS.Count < 7
> WS.Add([],WS.Item(WS.Count));
> end
> sheet1 = get(Sheets, 'Item', 1);
> sheet1.Activate;
> eRangeSTOP.NumberFormat = '@';
>
> STOP_TBL_idx = find(~cellfun('isempty',regexp(STOPCompareDiff,'_STOP_TBL')));
> for ii = 1:length(STOP_TBL_idx)-1
> set(sheet1.Range([num2str(STOP_TBL_idx(ii)+1) ':' num2str(STOP_TBL_idx(ii+1)-2)]),'Group',1)
> end
Found a solution; not sure if it is the best one though (no need to set(), just use Range.Group
for ii = 1:length(STOP_TBL_idx)-1
TempRange = Excel1.Activesheet.get('Range', [num2str(STOP_TBL_idx(ii)+1) ':' num2str(STOP_TBL_idx(ii+1)-2)]);
TempRange.Group
end