Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hello Noel,


starting with a workbook with the following sheets 'sheet1', 'sheet2' and
'sheet3'
and trying a macro like:

sub test
   worksheets.copy after:=worksheets(2)
end sub

results in the following sheets in the workbook 'sheet1', 'sheet2',
'sheet1_2', 'sheet2_2', 'sheet1_2_2', 'sheet3'
the expected result should be something like 'sheet1', 'sheet2',
'sheet1_2', 'sheet2_2', 'sheet3_2', 'sheet3'

and similarly running the following macro

sub test
   worksheets.copy before:=worksheets(2)
end sub

results in a workbook with the following sheets  'sheet1', 'sheet1_2',
'sheet1_2_2', 'sheet1_2_2_2', 'sheet2', 'sheet3'
expected results would be 'sheet1', 'sheet1_2', 'sheet2_2', 'sheet3_2',
'sheet2','sheet3'

I think you are falling victim to the fact that you are modifying the
underlying container ( e.g. the sheets container ) whilst iterating over it.


No I wasn't. I just used the method a bit different to you. It seems that
there are two possible ways a XWorksheets object is used. First is your use
case in which you specify to copy all sheets. I, in contrast, didn't know
that was possible and used the syntax provided by the bug report:
Sheets(Array(1,2,3)).Copy Before:=Sheets(2) which works fine because a new
worksheets object is created and you don't modify your own container.

Nevertheless my method doesn't work fine and I appreciate your help and will
rework my method. I'll have a look at your pseudo code and think a bit how I
can rework both copy methods.

Regards,
Markus

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.