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
| Sub EnregistrerNew()
'Définition des variables
Dim Nom As String
Dim Nom2 As String
Dim Nom3 As String
Dim Fichier As String
Fichier = ThisWorkbook.Path & "\" & Nom3
Nom3 = "Modele" & ".xls"
Nom = Range("A4") & ".xls"
Nom2 = Range("A4") & ".pdf"
If ThisWorkbook.Path = "" Then 'si le document n'a jamais été enregistré
SendKeys Nom
Application.Dialogs(xlDialogSaveAs).Show 'boîte de dialogue Enregistrer sous
Else
If Range("A4") = "" Then MsgBox "Entrez le nom du fichier en A4", 48: Range("A4").Select: Exit Sub
If MsgBox("Voulez-vous enregistrer le fichier sous le nom " & Nom & " ?", 4) = 6 Then
On Error Resume Next
ThisWorkbook.SaveAs ThisWorkbook.Path & "\" & Nom 'Enregistre dans le même dossier
If Err Then MsgBox "Fichier déjà existant", 48: Range("A4").Select
'Fixe les cellules et sauvegarde à nouveau
Range("A1:B3").Select
Selection.Copy
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Range("A1:B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ThisWorkbook.SaveAs ThisWorkbook.Path & "\" & Nom 'Enregistre dans le même dossier
'Crée le fichier PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & Nom2, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
From:=1, To:=4, OpenAfterPublish:=False
'Ferme le nouveau fichier sauvé
ThisWorkbook.Close
End If
End If
'Ouvrir le modèle
Workbooks.Open (Fichier)
End Sub |
Partager