• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

1004 RUN TIME ERROR

venkat1212

New Member
Hi Friends,
I want to make separate excel files for this.

upload_2017-12-7_14-47-18.png

I used the VBA code:

Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End

And the result is:
upload_2017-12-7_14-52-31.png
After Debug it is showing ike this,
upload_2017-12-7_14-53-6.png
how to resolve....


▬▬▬▬▬▬▬▬▬ Mod edit : thread moved to appropriate forum !
 
Welcome to the Forum.

Add debug.print line in code before SaveAs line to check string. Make sure that file name (i.e. sheet name) does not contain any illegal character.
Code:
Debug.Print xPath & "\" & ws.Name & ".xlsx"

While file format is optional, it's safer to add it as you are specifying to file extension ".xlsx" (i.e. FileFormat:=51 or xlOpenXMLWorkbook)

Other than that, code itself is fine.

Also as per error message, make sure that you have appropriate permission on the folder that you are saving new file on.
 
Back
Top