LOGO
General Discussion Undecided where to post - do it here.

Reply to Thread New Thread
Old 12-09-2011, 06:53 PM   #1
Neitteloxesia

Join Date
Oct 2005
Posts
350
Senior Member
Default excel help again
Can someone please let me know what's wrong with the following code? Sometimes it seems to work in excel and sometimes it doesnt and I'll get a 1004 error.
What the code does is show the hidden sheets, copy them, hide them and paste the sheets into a different and specified workbook.

Code:
Code
Sub Createstatistic()    Dim NewName As String    Dim nm As Name    Dim ws As Worksheet        If MsgBox("Copy specific sheets to a new workbook" & vbCr & _    "New sheets will be pasted as values, named ranges removed" _    , vbYesNo, "NewCopy") = vbNo Then Exit Sub         With Application        .ScreenUpdating = False                  '       Copy specific sheets         '       *SET THE SHEET NAMES TO COPY BELOW*         '       Array("Sheet Name", "Another sheet name", "And Another"))         '       Sheet names go inside quotes, seperated by commasOn Error GoTo ErrCatcher  For Each wsname In Array("DECKBLATT", "MGB STATS", "HRI STATS", "SRE STATS", "RCO STATS", "JUH AAM STATS", "KST STATS", "DRE STATS", "JCH STATS", "SLO STATS", "MSG STATS", "SVS STATS", "RSB STATS", "USO STATS", "PKR STATS", "SVS STATS", "PBO STATS", "CLG STATS", "ANE STATS", "MAK STATS", "RWA STATS", "YBO STATS", "HPA STATS", "KTZ STATS", "DWA STATS", "METALLE STATS", "OPTIONEN STATS", "TOTAL")    Worksheets(wsname).Visible = TrueNextSheets(Array("DECKBLATT", "MGB STATS", "HRI STATS", "SRE STATS", "RCO STATS", "JUH AAM STATS", "KST STATS", "DRE STATS", "JCH STATS", "SLO STATS", "MSG STATS", "SVS STATS", "RSB STATS", "USO STATS", "PKR STATS", "SVS STATS", "PBO STATS", "CLG STATS", "ANE STATS", "MAK STATS", "RWA STATS", "YBO STATS", "HPA STATS", "KTZ STATS", "DWA STATS", "METALLE STATS", "OPTIONEN STATS", "TOTAL")).CopySheets(Array("DECKBLATT", "MGB STATS", "HRI STATS", "SRE STATS", "RCO STATS", "JUH AAM STATS", "KST STATS", "DRE STATS", "JCH STATS", "SLO STATS", "MSG STATS", "SVS STATS", "RSB STATS", "USO STATS", "PKR STATS", "SVS STATS", "PBO STATS", "CLG STATS", "ANE STATS", "MAK STATS", "RWA STATS", "YBO STATS", "HPA STATS", "KTZ STATS", "DWA STATS", "METALLE STATS", "OPTIONEN STATS", "TOTAL")).Visible = FalseOn Error GoTo 0                                   '       Paste sheets as values         '       Remove External Links, Hperlinks and hard-code formulas         '       Make sure A1 is selected on all sheets        For Each ws In ActiveWorkbook.Worksheets            ws.Cells.Copy            ws.[A1].PasteSpecial Paste:=xlValues            ws.Cells.Hyperlinks.Delete            Application.CutCopyMode = False            Cells(1, 1).Select            ws.Activate        Next ws        Cells(1, 1).Select                  '       Remove named ranges        For Each nm In ActiveWorkbook.Names            nm.Delete        Next nm                  '       Input box to name new file        NewName = InputBox("Please Specify the name of your new workbook", "New Copy")                  '       Save it with the NewName and in the same directory as original         'Prompt for SaveAs name   ActiveWorkbook.SaveCopyAs ThisWorkbook.Path & "\" & NewName & ".xls"        ActiveWorkbook.Close SaveChanges:=False                 .ScreenUpdating = True    End With    Exit Sub     ErrCatcher:    MsgBox "Specified sheets do not exist within this workbook"    End Sub

Neitteloxesia is offline


Old 12-09-2011, 09:53 PM   #2
Erossycuc

Join Date
Oct 2005
Posts
388
Senior Member
Default
solved it.. problem was that it doesn't work when the sheets are protected..
Erossycuc is offline



Reply to Thread New Thread

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

All times are GMT +1. The time now is 07:53 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 PL2
Design & Developed by Amodity.com
Copyright© Amodity