<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Hi Markus<br>
On 09/04/11 01:37, Markus Mohrhard wrote:
<blockquote
cite="mid:BANLkTimUtHdMUrmkkh4KvSnW3q_+RQATag@mail.gmail.com"
type="cite">Hello Noel,<br>
<br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
<br>
starting with a workbook with the following sheets 'sheet1',
'sheet2' and 'sheet3'<br>
and trying a macro like:<br>
<br>
sub test<br>
worksheets.copy after:=worksheets(2)<br>
end sub<br>
<br>
results in the following sheets in the workbook 'sheet1',
'sheet2', 'sheet1_2', 'sheet2_2', 'sheet1_2_2', 'sheet3'<br>
the expected result should be something like 'sheet1',
'sheet2', 'sheet1_2', 'sheet2_2', 'sheet3_2', 'sheet3'<br>
<br>
and similarly running the following macro<br>
<br>
sub test<br>
worksheets.copy before:=worksheets(2)<br>
end sub<br>
<br>
results in a workbook with the following sheets 'sheet1',
'sheet1_2', 'sheet1_2_2', 'sheet1_2_2_2', 'sheet2', 'sheet3'<br>
expected results would be 'sheet1', 'sheet1_2', 'sheet2_2',
'sheet3_2', 'sheet2','sheet3'<br>
<br>
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.<br>
</blockquote>
</div>
<br>
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.<br>
</blockquote>
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<br>
<blockquote
cite="mid:BANLkTimUtHdMUrmkkh4KvSnW3q_+RQATag@mail.gmail.com"
type="cite">
<br>
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.<br>
</blockquote>
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 :-)<br>
<br>
thanks,<br>
Noel<br>
</body>
</html>