Copy a worksheet into a new work book in xlsm format

I have a workbook with 10 different work sheet. I would like to copy only one worksheet into a new workbook. I am using excel 2010.  The sheet name is Trial. Only the records with a sheet name of "trail" should be copied. Rest should not be copied. The output workbook should be saved with the sheet name.
For example: Trail.xlsm.
I prefer the output to be saved in xlsm format.
Thanks.
karthik80cAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dani gammonProduct Operations ManagerCommented:
Hi there,

*Right-click on the worksheet tab you want to copy.
*Click-on "Move or Copy"
*Make sure that the right worksheet is selected
*On: "Move selected sheets To book: choose the new workbook.
*Click on "Create a copy"
*Click OK

You will have a copy of the worksheet in the new workbook.  You will have to save the new workbook.

Hope this helps!The
0
MacroShadowCommented:
Do you want this done with VBA or manually?
0
Randy PooleCommented:
Sub CopySheet()
    Dim xls As Excel.Worksheet
    
    For Each xls In ActiveWorkbook.Sheets
        If UCase(xls.Name) = "TRIAL" Then
            Dim xlb As Excel.Workbook
            Set xlb = Workbooks.Add()
            xls.Copy Before:=xlb.Sheets("Sheet1")
            xlb.SaveAs "TRIAL.xlsm", xlOpenXMLWorkbookMacroEnabled
            xlb.Close (True)
        End If
    Next xls
End Sub

Open in new window


Just add this as a macro
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

NorieVBA ExpertCommented:
All you need to copy a worksheet named 'Trail' to a new workbook and save it in xlsm format is this.ldmis this.
Sheets("Trail).Copy

ActiveWorkbook.SaveAs Filename:="Trail.xlsm", FileFormat:=54

Open in new window

0
karthik80cAuthor Commented:
Thank you imnorie and randy. The issue I am facing the excel sheet gets hanged while doing to save into a new workbook.
The excel sheet has lot of data for different sheets. But this sheet has only 5 records. Other than that there are other macros for different purposes. But I am executing only this sheet macro. It still gets hanged while trying to save.
0
karthik80cAuthor Commented:
dani and Macro...
I am looking for VBA code not manually. Thank you for replying to my post. Appreciate it.
0
Randy PooleCommented:
It is possible you are getting a save conflict,try this:
Sub CopySheet()
    Dim xls As Excel.Worksheet
    
    For Each xls In ActiveWorkbook.Sheets
        If UCase(xls.Name) = "TRIAL" Then
            Dim xlb As Excel.Workbook
            Set xlb = Workbooks.Add()
            xlb.Application.DisplayAlerts = False
            xls.Copy Before:=xlb.Sheets("Sheet1")
            xlb.SaveAs "TRIAL.xlsm", xlOpenXMLWorkbookMacroEnabled, AccessMode:=xlExclusive, ConflictResolution:=Excel.XlSaveConflictResolution.xlLocalSessionChanges
            xlb.Close False
        End If
    Next xls

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
karthik80cAuthor Commented:
Thank you so much Randy for a quick reply. But the code still hangs. I did try your code.
0
Randy PooleCommented:
Does the file "TRIAL.xlsm" exist in the directory your workbook that is running the macro resides in?
0
karthik80cAuthor Commented:
yes. Randy. It is in the same location.
0
Randy PooleCommented:
If you delete that file before running the macro does the macro still freeze?
0
karthik80cAuthor Commented:
Yes. Randy. It still freezes. :(  Thank you so much for your support.
0
Randy PooleCommented:
Hmm, can you upload the workbook so I can try it
0
karthik80cAuthor Commented:
I cannot do that as it fails only in the client system. He does not share the whole file with me as it is confidential. But your code is perfectly good so I will accept you as the solution. Only issue is its failing due to that excel sheet having too many macros and records. Thanks again for your effort and help. Appreciate it.
0
karthik80cAuthor Commented:
Good work. Appreciate his handwork in helping to resolve the issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

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.