LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Copy sheets macro error

I wrote some code to make copies of a worksheet when opening a file. The
number of copies is based on user input on a userform. I'm now trying to do
the same thing in a different workbook, but I'm getting unexpected errors.

The way it is supposed to work: When opening the workbook, the user enters a
number on a userform. When they click submit on the userform, the number is
passed to the CopySheets sub (code below). The code makes copies of the
Original sheet, lists the names of the copies on the Master sheet, hides the
Original sheet, and then Saves the file using GetSaveAsFilename method.

Here is what is actually happening: The sheets copy correctly, the file is
saved, and then I get the error "Method 'Copy' of object '_Worksheet'
failed." When I click Debug, the line highlighted is:
WS.Copy befo=Worksheets("MyChart").

Sub CopySheets(ByVal Copies As Integer)
Dim Original As Worksheet
Dim Master As Worksheet
Dim i As Integer
Dim fSaveName As Variant
Set Original = ThisWorkbook.Worksheets("Original")
Set Master = ThisWorkbook.Worksheets("Master")

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False

ThisWorkbook.Unprotect
Master.Unprotect
For i = 1 To Copies
Original.Copy befo=Worksheets("MyChart")
ActiveSheet.Name = "Copy" & i
Master.Range("A" & i) = "Copy" & i
Next i
Original.Visible = xlSheetVeryHidden
Master.Protect
ThisWorkbook.Protect

WhereToSave:
Do
fSaveName = Application.GetSaveAsFilename
Loop Until fSaveName < False

Application.DisplayAlerts = False
ThisWorkbook.SaveAs fSaveName
Application.DisplayAlerts = True

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy and Paste with Macro Between sheets jlclyde Excel Discussion (Misc queries) 1 November 8th 07 05:07 PM
Compare two wk sheets with common data using copy paste macro conejo Excel Worksheet Functions 0 October 8th 07 09:21 AM
Copy-Paste sheets - error in the dates Aninha Excel Worksheet Functions 1 February 28th 06 04:04 PM
Copy Sheets Macro WBTKbeezy Excel Worksheet Functions 8 February 24th 06 07:53 PM
Macro Error when moved Xcel Sheets from User's Home Dir to Networ Basheer New Users to Excel 1 April 29th 05 04:45 PM


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"