Perhaps Chip's macro can help you:
http://www.cpearson.com/excel/sortws.htm
"(E-Mail Removed)" wrote:
> I want to arrange the worksheets in a Excel worbook in alphabetical
> order. I read the worksheet names into a list and sort it. When I try
> to rearrange I am having problems. I get a run-time error "Move method
> of worksheet class failed"
>
> Any help will be appreciated.
> Thanks,
> Sunil
>
> Code snippet:
>
> long int numSheets;
> CWorksheets Sheets;
> CWorksheet wSheet;
> Sheets = oBook.get_Worksheets( );
> numSheets = Sheets.get_Count( );
>
> for ( int i=1;i<=numSheets;i++ )
> {
> wSheet = Sheets.get_Item( COleVariant( (short)(i) ) );
> wSheet.Activate( );
> tmpName = wSheet.get_Name();
> //AfxMessageBox( tmpName.c_str() );
> if ( ( tmpName != "VE_Dump" ) && ( tmpName != "Summary"
> ) )
> sheetNames.push_back( tmpName );
> }
>
> sheetNames.sort( );
> //trial to see it it works
> wSheet = Sheets.get_Item( COleVariant( (short)(1) ) );
> wSheet.Move( COleVariant( (short)(3) ), covOptional );
>
>