[Libreoffice] [Patch]Add method Copy to ScVbaWorksheets

Noel Power nopower at novell.com
Mon Apr 11 01:33:13 PDT 2011


Hi Markus
On 09/04/11 01:37, Markus Mohrhard wrote:
> 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.
aha, sorry, I didn't even look at the book just coded the first example 
that came into my head, and yeah in this scenario the container you are 
iterating over and the container you are modifying are different
>
> 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.
Ok, looking at the example you used I *think* my suggestion should still 
work with this case too. But.... please don't be afraid to completely 
disregard my idea, I am sure there is more than one way to solve the 
problem, my main concern is that we reuse the same functionality, 
besides being good coding ( something I don't claim to be good at ) in 
this case it really seems that such reuse should be the natural 
solution, if you find a ( better/easier/personal preference ) way that 
works for you then go for it :-)

thanks,
Noel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20110411/6a0b8138/attachment.htm>


More information about the LibreOffice mailing list