1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
Option Explicit
Sub Création_feuille()
Dim A As String
Dim B As String
Dim DernLig As Long
Dim S As String
Dim Wbk As Workbook
'Copie les données
Windows("fichier_entree.xlsm").Activate
Columns("A:C").Copy
'Copie du code du module 2
With ActiveWorkbook.VBProject.VBComponents("Module2").CodeModule
S = .Lines(1, .CountOfLines)
End With
'Création du nom de la feuille
A = Left(Cells(2, 4).Value, 6)
B = Right(A, 2)
N = Left(Cells(2, 1).Value, 4) & " SS " & B
'Détermine le nombre de ligne non vide
DernLig = Cells(Cells.Rows.Count, "A").End(xlUp).Row
'Création de la nouvelle feuille
Workbooks.Open ("C:\Users\Vivien\Desktop\VBA\SuiviDeProduction\Suivi_de_Production.xlsm")
Sheets.Add After:=Sheets(Sheets.Count)
'Coller les données
Range("A1").Select
ActiveSheet.Paste
'Création de la colonne Ligne
Range("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Value = "LIGNE"
With Range("A1")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
Range("B1").Copy
Range("A1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With
'Création colonne poste 1
Range("E1").Select
ActiveCell.FormulaR1C1 = "Obj."
Range("F1").Select
ActiveCell.FormulaR1C1 = "Poste 1"
With Range("E1:F1")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
Range("B1").Copy
Range("E1:F1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With
'Renomme la nouvelle feuille
ActiveSheet.Name = (N)
'Copie du code du module 2 dans la feuil1 (Liste)
With Wbk.VBProject.VBComponents(Sheets(Sheets.Count)).CodeModule
.AddFromString S
End With
'Ferme le fichier de suivi de prod
Windows("Suivi_de_Production.xlsm").Activate
ActiveWorkbook.Save
ActiveWindow.Close
End Sub |
Partager