Add sheets (Excel 2003)

E

ejc

Hello,
Why does'nt it work ? :
.....
Sheets("Sem00").Copy After:=Sheets(Sheets.Count)
.....
I have this error :
La méthode Copy de la classe Worksheet à échoué
(in english : The Copy method of the WorkSheeet Class fail)
Normalement, je dois ainsi ajouter 53 feuilles (semaines de planning).
(I have to add 53 sheets (weeks))
Sometimes, I can add 15 sheets, sometimes 30, but never the 53 sheets...
If somebody can help, thank's in advance
Sorry for my english
ejc
 
A

AltaEgo

Possibly sheet Sem00 does not exist, therefore it cannot be copied.


Sub CopyOrAddWs()
Dim ws As Worksheet
On Error Resume Next
Set ws = Sheets("Sem00")
On Error GoTo 0
If ws Is Nothing Then
'does not exist, therefore create
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Sem00"

Else
'does exist
Sheets("Sem00").Copy After:=Sheets(Sheets.Count)
End If

End Sub
 
J

Jim Cone

Some of these can probably still be had...

Copying Worksheet Programmatically Causes Run-Time Error 1004 in Excel
http://support.microsoft.com/default.aspx?scid=kb;en-us;210684
XL97: Copy Method of Sheets Object Causes Invalid Page Fault
http://support.microsoft.com/default.aspx?scid=kb;en-us;177634
XL97: Excel Quits Unexpectedly Running Macro That Creates Chart
http://support.microsoft.com/?kbid=186219
You receive an error message when you add a chart to a workbook in Excel
http://support.microsoft.com/kb/215573/en-us

The most popular solution seems to be to create a template (.xlt) and
copy that. Use "Sheets" not "Worksheets" when copying.
--
Jim Cone
Portland, Oregon USA




"ejc"
<[email protected]>
wrote in message
Hello,
Why does'nt it work ? :
.....
Sheets("Sem00").Copy After:=Sheets(Sheets.Count)
.....
I have this error :
La méthode Copy de la classe Worksheet à échoué
(in english : The Copy method of the WorkSheeet Class fail)
Normalement, je dois ainsi ajouter 53 feuilles (semaines de planning).
(I have to add 53 sheets (weeks))
Sometimes, I can add 15 sheets, sometimes 30, but never the 53 sheets...
If somebody can help, thank's in advance
Sorry for my english
ejc
 
Top