excel saving to xlstart

rikvny02

Board Regular
Joined
Aug 9, 2022
Messages
78
Office Version
  1. 365
Platform
  1. Windows
Can someone help. Why are my sheets saving to the XLstart folder instead of the folder path with the original file. Thanks in advance

Private Sub CreateWorkbooks()

Dim WB As Workbook

Dim ws As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False

For Each ws In Worksheets

ws.Copy

Set WB = ActiveWorkbook

WB.SaveAs ThisWorkbook.Path & "\" & ws.Name, FileFormat:=52

WB.Close

Next ws

End Sub
 
Does it fail on ALL sheets, or just certain ones?

Try showing all alerts initially. Suppressing them can sometimes hide important error information.
Also, let's add a little error handling to see if we can get more information.

Try running this version, and let us know what the message box returns, and let us know if it saved any sheets at all.
VBA Code:
Private Sub CreateWorkbooks()

Dim WB As Workbook
Dim ws As Worksheet

'Application.ScreenUpdating = False
Application.DisplayAlerts = True

On Error GoTo err_chk
For Each ws In Worksheets
    ws.Copy
    Set WB = ActiveWorkbook
    WB.SaveAs "H:\balances\" & ws.Name, FileFormat:=52
    WB.Close
Next ws

Exit Sub

err_chk:
    MsgBox Err.Number & ":" & Err.descrtion & vbCrLf & ws.Name
    
End Sub
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
unfortunately i'm getting the same error. do you think the file could be corrupt?
Hi
untested but see if this update to your code resolves your issue

VBA Code:
Private Sub CreateWorkbooks()
    Dim wb          As Workbook
    Dim ws          As Worksheet
    
    Const strFilePath As String = "H:\balances\"
    
    On Error GoTo myerror
    With Application
        .ScreenUpdating = False: .DisplayAlerts = False
    End With
    
    For Each ws In ThisWorkbook.Worksheets
    
        ws.Copy
        Set wb = ActiveWorkbook
        
        wb.SaveAs strFilePath & ws.Name & ".xlsx", FileFormat:=51
        
        wb.Close False
        Set wb = Nothing
        
    Next ws
    
myerror:
    If Not wb Is Nothing Then wb.Close False
    With Application
        .ScreenUpdating = True: .DisplayAlerts = True
    End With
    If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub

Dave
 
Upvote 0
Not sure the reason but I needed to recreate the Original file and Folder. Then the below VBA worked correctly. Thanks to everyone for the help.

Private Sub CreateWorkbooks()

Dim wb As Workbook

Dim ws As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False

For Each ws In Worksheets

ws.Copy

Set wb = ActiveWorkbook

wb.SaveAs ThisWorkbook.Path & "\" & ws.Name, FileFormat:=52

wb.Close

Next ws

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,073
Messages
6,122,974
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top