ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Method Add of object Sheet failed (https://www.excelbanter.com/excel-programming/366669-method-add-object-sheet-failed.html)

JonMitsu

Method Add of object Sheet failed
 

code example:

Private Sub CommandButton1_Click()
Dim filename As String
Dim i As Integer

Sheets.Add Type:="C:\MyBook.xls"
Sheets(1).Select
Sheets(1).Move
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs filename:="C:\MyBook.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
Application.DisplayAlerts = False
Workbooks(1).Activate
Sheets(1).Select

End Sub

--When I press the button 7 times VB Show Error message:
--Run-time error 1004:
--Method Add of object Sheet failed

Please help. WHY DO THIS PROBLEM

--
JonMits
-----------------------------------------------------------------------
JonMitsu's Profile: http://www.excelforum.com/member.php...fo&userid=3618
View this thread: http://www.excelforum.com/showthread.php?threadid=55962


Don Guillett

Method Add of object Sheet failed
 
Sheets.Add Type:="Worksheet"
It might help for you to tell us exactly what you are trying to do.

--
Don Guillett
SalesAid Software

"JonMitsu" wrote in
message ...

code example:

Private Sub CommandButton1_Click()
Dim filename As String
Dim i As Integer

Sheets.Add Type:="C:\MyBook.xls"
Sheets(1).Select
Sheets(1).Move
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs filename:="C:\MyBook.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
Application.DisplayAlerts = False
Workbooks(1).Activate
Sheets(1).Select

End Sub

--When I press the button 7 times VB Show Error message:
--Run-time error 1004:
--Method Add of object Sheet failed

Please help. WHY DO THIS PROBLEM?


--
JonMitsu
------------------------------------------------------------------------
JonMitsu's Profile:
http://www.excelforum.com/member.php...o&userid=36188
View this thread: http://www.excelforum.com/showthread...hreadid=559622




JonMitsu[_2_]

Method Add of object Sheet failed
 

I try to do:

1. Open workbook MyBook.xls in My Activeworkbook.
Do changes in new sheet.
2. Save New Sheet in File MyBooks.xls

Sorry but my english speak is Zero:) i can't say that i want.


--
JonMitsu
------------------------------------------------------------------------
JonMitsu's Profile: http://www.excelforum.com/member.php...o&userid=36188
View this thread: http://www.excelforum.com/showthread...hreadid=559622


Don Guillett

Method Add of object Sheet failed
 
Recorded
Sub Macro7()
'
' Macro7 Macro
' Macro recorded 7/8/2006 by Don Guillett
'

'
Workbooks.Open filename:="C:\yourfolder\yourfilename.xls"
Sheets("Sheet2").Select
Sheets("Sheet2").Move' you might prefer .copy
ActiveWorkbook.SaveAs filename:="C:\yourfolder\newbooks.xls",
FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close
End Sub


--
Don Guillett
SalesAid Software

"JonMitsu" wrote in
message ...

I try to do:

1. Open workbook MyBook.xls in My Activeworkbook.
Do changes in new sheet.
2. Save New Sheet in File MyBooks.xls

Sorry but my english speak is Zero:) i can't say that i want.


--
JonMitsu
------------------------------------------------------------------------
JonMitsu's Profile:
http://www.excelforum.com/member.php...o&userid=36188
View this thread: http://www.excelforum.com/showthread...hreadid=559622





All times are GMT +1. The time now is 05:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com