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
| Sub test()
Dim c As Range
Application.ScreenUpdating = False
For Each c In Range("a2:a5")
'designe mon fichier de destination
Dim Dossier As String, Fichier As String, Chemin As String
Dossier = "d:\spain\"
Fichier = "Dessin.xlsx"
Chemin = Dossier & Fichier
Dim Presence As Boolean
Presence = False
For Each w In Workbooks
If w.Name = Fichier Then Presence = True
Next w
If Presence = True Then
Workbooks(Fichier).Activate
Else
'Ouvre en automatique mon fichier de destination avec le mot de passe indiqué
Workbooks.Open Chemin, , , , "dessin"
End If
' copie mo For Each c
If c <> "" Then
Sheets(2).Select
Range("c65536").End(xlUp).Offset(1, 0).Value = c
End If
Next
'Sheets(1).Select
'enregistre mon fichier de destination
If MsgBox("Do you want to create this file from Local line Spain ?", vbQuestion + vbYesNo, "Warning !!!!") = vbYes Then
' TON CODE SI LA REPONSE EST "OUI"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="d:\spain\Dessin.xlsx "
ActiveWorkbook.Close
ActiveWorkbook.SaveAs Filename:="d:\spain\WO_DESS " & Format(Date, "dd_mm_yyyy") & "_" & Format(Time, "hhmm"), Password:="", WriteResPassword:="", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
ActiveWorkbook.Close
'ferme et ne sauvegarde pas mon fichier de creation
Application.DisplayAlerts = False
Application.DisplayAlerts = True
ActiveWorkbook.Close savechanges:=False
ActiveWorkbook.Close
Else
' TON CODE SI LA REPONSE EST "NON"
ActiveWorkbook.Close savechanges:=False
End If
End Sub |
Partager