• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

Excel Macro

Hello,
Can you please help,
I'm using below code to save sheets to new workbook.
the problem I have is, the sheet names are not always the same.

how can I change the code below to say,
Copy All sheets except "Main_Sheet"

Sub Export()
     
    Dim wb As Workbook, InitFileName As String, fileSaveName As String
    InitFileName = ThisWorkbook.Path & "\ - Recon_Output_ " & Format(Date, "yyyymmdd")
     Sheets(Array("SheetM1", "SheetMG1", "SheetHM1", "SheetJM1", "SheetK1", "SheetO1", "SheetL1", "SheetJY91")).Copy
    Set wb = ActiveWorkbook
      With wb
        .SaveAs "C:\Users\Wassim\Desktop\test)
        .Close False
    End With
    Range("A1").Select
    ActiveWorkbook.SAVE
End Sub

Any help is appreciated,
Thanks
0
W.E.B
Asked:
W.E.B
1 Solution
 
Rgonzo1971Commented:
HI,

pls try

Sub Export()
      
     Dim wb As Workbook, InitFileName As String, fileSaveName As String
     InitFileName = ThisWorkbook.Path & "\ - Recon_Output_ " & Format(Date, "yyyymmdd")
    Dim arrSheets As Variant
    For Each sh In ActiveWorkbook.Sheets
        If sh.Name <> "Main_Sheet" Then
            strSheets = strSheets & sh.Name & ","
        End If
    Next
    strSheets = Left(strSheets, Len(strSheets) - 1)
    arrSheets = Split(strSheets, ",")
    Sheets(arrSheets).Copy

     Set wb = ActiveWorkbook
       With wb
         .SaveAs "C:\Users\Wassim\Desktop\test)
         .Close False
     End With
     Range("A1").Select
     ActiveWorkbook.SAVE
 End Sub

Open in new window

Regards
0
 
W.E.BAuthor Commented:
Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now