Hello everyone,
I've got sub that creates workbooks from sheets. My sheets have names in the form of dates in with format yyyy.mm.dd (2021.01.15 - for example).
Routine does creates files, but they come with names like 2021.01.20 without extensions (it should be 2021.01.20.xlsx) and can not be opened by Excel. When I try to rename them manually, they open with sheets empty, without any data. I would be grateful if you could help me to find out reason for that. Thanks in advance.
Dilshod
Code
- Sub CreateWorkbookFromSheets()
- Dim ws As Worksheet
- Dim wb As Workbook
- Dim path As String
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- path = "C:\VBA\SMA4\Control Files SMA4\Files with orders"
- For Each ws In ThisWorkbook.Worksheets
- If Not ws.Name Like "*T" And ws.Name <> "Sheet1" Then
- Set wb = Workbooks.Add
- wb.SaveAs path & "\" & ws.Name
- ws.Copy before:=wb.Worksheets(1)
- wb.Close savechanges = True
- End If
- Next ws
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub