Я борюсь за то, как отсортировать листы после объединения всех книг в 1.
вот мой код:
Dim wbDst As Workbook
Dim wbSrc As Workbook
Dim wsSrc As Worksheet
Dim mypath As String
Dim strFilename As String
Dim saveFolder As String
Dim i%, j%
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.AskToUpdateLinks = False
mypath = "C:\Acct. Docs" 'Change to suit
Set wbDst = Workbooks.Add(xlWBATWorksheet)
strFilename = Dir(mypath & "\*.xlsx", vbNormal)
Dim fname As String
saveFolder = "C:\FORMATTED"
If Len(strFilename) = 0 Then Exit Sub
Do Until strFilename = ""
Set wbSrc = Workbooks.Open(Filename:=mypath & "\" & strFilename)
Set wsSrc = wbSrc.Worksheets(1)
wsSrc.Copy After:=wbDst.Worksheets(wbDst.Worksheets.Count)
wbSrc.Close False
For i = 1 To wbDst.Worksheets.Count - 1
For j = 1 To wbDst.Worksheets.Count
If wbDst.Worksheets(j).Name < wbDst.Worksheets(i + 1).Name Then
wbDst.Worksheets(j).Move Before:=Sheets(i + 1)
End If
Next j
Next i
strFilename = Dir()
Loop
wbDst.Worksheets(1).Delete
fname = Sheets("Sheet1").Range("C5").Text
ActiveWorkbook.SaveAs saveFolder & "\" & fname & " Account Documentation.xlsx", FileFormat:=51
wbDst.Close
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Я хочу, чтобы листы были отсортированы по алфавиту. заранее спасибо!!