J'ai un script qui fait un vlookup pour chaque feuille dans le classur, puis divise chaque feuille de calcul dans son propre file. J'ai le script ci-dessous, mais ça ne fonctionne pas. La partie vlookup fonctionne bien, mais j'ai des problèmes avec la scission. Il ne manque pas et me donne une erreur, ça ne fait rien.
Sub Splitbook() MyPath = "***Folder Location***" For Each sht In Workbooks("PO135 Division 1.xlsx").Worksheets sht.Copy ActiveSheet.Cells.Copy ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues ActiveSheet.Cells.PasteSpecial Paste:=xlPasteFormats ActiveWorkbook.SaveAs _ Filename:=MyPath & "\" & sht.Name & ".xlsx" ActiveWorkbook.Close savechanges:=False Next sht End Sub
J'ai besoin de split les files, puis les sauvegarder dans un dossier distinct (" Emplacement des dossiers ") – ce n'est qu'un espace réservé pour le moment, il serait mis à jour avant d'exécuter le script.
Des pensées? Appréciez l'aide!
Mettez cela dans un module régulier:
Sub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Sub NewWb ()Sub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Dim ws As WorksheetSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Dim wbActive As WorkbookSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Dim wbNew As WorkbookSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Dim x As SingleSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Application.ScreenUpdating = FalseSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Définir wbActive = ActiveWorkbookSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Pour chaque ws dans wbActive.WorksheetsSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Définir wbNew = Workbooks.AddSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
ws.Copy Before: = wbNew.Sheets (1)Sub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
abc = "C: \ Files \" & ws.Name & ".xlsx"Sub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Application.DisplayAlerts = FalseSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
wbNew.Sheets ("Sheet1"). SupprimezSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Application.DisplayAlerts = TrueSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
wbNew.SaveAs Nom de file: = abcSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
wbNew.Close Saved = TrueSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Next wsSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Set ws = NothingSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Définir wbActive = NothingSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Set wbNew = NothingSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub
Application.ScreenUpdating = TrueSub NewWb() Dim ws As Worksheet Dim wbActive As Workbook Dim wbNew As Workbook Dim x As Single Application.ScreenUpdating = False Set wbActive = ActiveWorkbook For Each ws In wbActive.Worksheets Set wbNew = Workbooks.Add ws.Copy Before:=wbNew.Sheets(1) abc = "C:\Files\" & ws.Name & ".xlsx" Application.DisplayAlerts = False wbNew.Sheets("Sheet1").Delete Application.DisplayAlerts = True wbNew.SaveAs Filename:=abc wbNew.Close Saved = True Next ws Set ws = Nothing Set wbActive = Nothing Set wbNew = Nothing Application.ScreenUpdating = True End Sub