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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
Option Explicit
'---------------------------------------------------------------------------------------
' Procedure : Worksheet_SelectionChange
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet d'appeler Userform2 pour permettre d'entrer les dates en B18 et E18
'---------------------------------------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B18,E18")) Is Nothing Then UserForm2.Show
End Sub
'---------------------------------------------------------------------------------------
' Procedure : Worksheet_Change
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet de récupérer les données de Liste et BDD dans contrat en fonction du N° de commande
' Permet aussi de remplir spot time
'---------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, v As Range
Dim Client As String
Dim TbLst, TbCli
Dim i As Byte
TbLst = Array("E7", "B10", "B8", "B18", "E18", "E12", "B19", "E19", "B30", "A22", "A24", "E10", "A27", "D30", "E31", "C32", "C33", "C34", "E44", "B44")
TbCli = Array("B11", "B12", "B13", "B14", "B15", "B16")
If Target.Address(0, 0) = "E8" Then
If Target.Value <> "" Then
Set c = Sheets("Liste").Range("A:A").Find(Target.Value, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
LaLigne = c.Row
Client = c.Offset(0, 2).Value
MsgBox "La commande n°: " & Target.Value & " du client: " & Client & " existe déjà, OK pour modifier"
For i = 0 To UBound(TbLst)
Range(TbLst(i)).Value = Sheets("Liste").Cells(LaLigne, i + 2).Value
Next i
If Client <> "" Then
Set v = Sheets("BDD Clients").Range("A:A").Find(Client, LookIn:=xlValues, lookat:=xlWhole)
If Not v Is Nothing Then
For i = 0 To UBound(TbCli)
If i <> 6 Then
'If i <> 5 Then
Range(TbCli(i)).Value = Sheets("BDD Clients").Cells(v.Row, i + 2).Value
Else
Range(TbCli(i)).Value = Range(TbCli(i - 1)).Value & " " & Sheets("BDD Clients").Cells(v.Row, i + 2).Value
End If
'End If
Next i
Set v = Nothing
End If
End If
Set c = Nothing
End If
End If
ElseIf Target.Address(0, 0) = "B19" Then
Application.EnableEvents = False
If Target.Value <> "" Then Range("E15").Value = DateAdd("n", -15, Target.Value)
Application.EnableEvents = True
End If
End Sub
'---------------------------------------------------------------------------------------
' Procedure : RAZ
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet d'effacer les cellules de Contrat (Ces cellules sont nommés MAPLAGE)
'---------------------------------------------------------------------------------------
Private Sub RAZ()
Dim c As Range
Application.EnableEvents = True
Application.ScreenUpdating = False
With Sheets("Contrat")
For Each c In .Range("MAPLAGE")
If Not c.HasFormula Then c.MergeArea.ClearContents
Next c
.Range("D30").Value = 0
.Range("E8").Select
End With
End Sub
'---------------------------------------------------------------------------------------
' Procedure : btnNEWCOM_Click
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet d'ajouter un nouveau n° de commande
'---------------------------------------------------------------------------------------
Private Sub btnNEWCOM_Click()
Dim LastLig As Long, NewCom As Long
If MsgBox("Voulez-vous ajouter une nouvelle commande?", vbYesNo) = vbYes Then
'Vider la formulaire
RAZ
With Worksheets("Liste")
'Dernière cellule remplie de colonne A feuille Liste
LastLig = .Cells(.Rows.Count, 1).End(xlUp).Row
'Incrémenter le n° de commande
NewCom = Val(.Range("A" & LastLig).Value) + 1
End With
With Worksheets("Contrat")
'ecriture dans la cellule E8 de "Contrat" du nouveau numero
.Range("E8").Value = NewCom
'ecriture de la date en B8...
.Range("B8").Value = Date
End With
'message qui dit le dernier num de commande et le nouveau...
MsgBox "Dernière commande : " & NewCom - 1 & vbCrLf & "Nouvelle commande : " & NewCom, vbInformation
End If
End Sub
'---------------------------------------------------------------------------------------
' Procedure : btnCLIENT_Click
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet d'ouvrir Userform1
'---------------------------------------------------------------------------------------
Private Sub btnCLIENT_Click()
UserForm1.Show
End Sub
'---------------------------------------------------------------------------------------
' Procedure : Impression
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet l'impression du contrat en pdf
'---------------------------------------------------------------------------------------
Private Sub Impression(ByVal Fichier As String)
With ThisWorkbook
If MsgBox("Voulez-vous imprimer la commande?", vbYesNo) = vbNo Then Exit Sub
'Ne pas imprimer
ThisWorkbook.Sheets("Contrat").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & Fichier & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Application.DisplayAlerts = True
End With
End Sub
'---------------------------------------------------------------------------------------
' Procedure : Mailing
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet la mailing
'---------------------------------------------------------------------------------------
Private Sub Mailing(ByVal FichierPDF As String)
' Attention, cocher la référence Microsoft Outlook XX.X Object Library
Dim OlApp As New Outlook.Application
Dim Rdv As Outlook.AppointmentItem
Dim ol As New Outlook.Application
Dim olmail As MailItem
Dim CurrFile As String
If MsgBox("Voulez-vous envoyer la commande par courriel?", vbYesNo) = vbNo Then Exit Sub
' Ne pas envoyer la commande
Shell "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"
' Ouvrir Outlook préalablement
Set Rdv = OlApp.CreateItem(olAppointmentItem)
With Rdv
.MeetingStatus = olNonMeeting
.Importance = olImportanceNormal
.Subject = Worksheets("Contrat").Range("E8").Text
.Body = Worksheets("Contrat").Range("B10").Text & " --> " & Worksheets("Contrat").Range("A24").Text
.Location = ""
.Start = Format(Worksheets("Contrat").Range("B18"), "yyyy/mm/dd")
.Duration = 30 'minutes
.Categories = ""
.Display
End With
Set OlApp = Nothing
'envoyer fichier PDF par courriel et signature
Set ol = New Outlook.Application
Set olmail = ol.CreateItem(olMailItem)
With olmail
.To = "cahoule@skyportinternational.com" 'adresse destinataire
.Subject = "Nouvelle commande ou modification" 'ici le sujet
.BodyFormat = olFormatHTML
.HTMLBody = "Bonjour Carmenne, SVP préparer/modifier la commande ci-jointe.<br><br>" & GetBoiler("C:\Users\Claude Dorion\AppData\Roaming\Microsoft\Signatures\Skyport.htm") 'ici le corps du mail et signature
.Attachments.Add ThisWorkbook.Path & "\" & FichierPDF & ".pdf" 'ici la pièce jointe
.Display '.Display /Send : Display correspond à l'affichage du message / Send demande un envoie direct
End With
End Sub
Function GetBoiler(ByVal sFile As String) As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
'---------------------------------------------------------------------------------------
' Procedure : btnCREECOM_Click
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet la sauvegarde/ modification de la commande dans feuille Liste
'---------------------------------------------------------------------------------------
Private Sub btnCREECOM_Click()
Dim NomFichier As String, Num As String
Dim c As Range
Dim i As Byte
Dim TbLst
Application.ScreenUpdating = False
'***** test si ligne commande existe deja *****
With Worksheets("Liste")
Num = Worksheets("Contrat").Range("E8").Value
If Trim(Num) <> "" Then
Set c = .Range("A:A").Find(Num, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
'SI LIGNE EXISTE DEJA, alors message d'alerte et sortie de la macro
LaLigne = c.Row
Set c = Nothing
If MsgBox("La commande " & Num & " est déjà enregistrée. Voulez-vous la modifier?", vbYesNo + vbDefaultButton2 + vbExclamation) = vbNo Then Exit Sub
Else
'***** Initialisation de la ligne vers la quelle les donnees de la nvelle commande seront ecrites *****
LaLigne = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
End If
'***** Creation du fichier *****
'creation du futur nom du fichier = "nom client" + " - " + "numero de commande"
With Worksheets("Contrat")
NomFichier = .Range("E8").Text & " - " & .Range("B10").Text
End With
''*****Sauvegarde
Impression NomFichier
''*****Mailing
Mailing NomFichier
'***** Mise a jour de la Liste *****
TbLst = Array("E8", "E7", "B10", "B8", "B18", "E18", "E12", "B19", "E19", "B30", "A22", "A24", "E10", "A27", "D30", "E31", "C32", "C33", "C34", "E44", "B44")
For i = 0 To UBound(TbLst)
.Cells(LaLigne, i + 1) = Worksheets("Contrat").Range(TbLst(i)).Value
Next i
End If
End With
LaLigne = 0
End Sub
'---------------------------------------------------------------------------------------
' Procedure : btnEFFACE_Click
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet d'effacer la feuille contrat (appel de RAZ)
'---------------------------------------------------------------------------------------
Private Sub btnEFFACE_Click()
RAZ
End Sub
'---------------------------------------------------------------------------------------
' Procedure : btnSUPPR_Click
' Author : Administrateur
' Date : 07/03/2011
' Purpose : Permet de supprimer la commande affichée
'---------------------------------------------------------------------------------------
Private Sub btnSUPPR_Click()
Dim Num As String
Dim c As Range
Application.ScreenUpdating = False
'***** test si ligne commande existe deja *****
With Worksheets("Liste")
Num = Worksheets("Contrat").Range("E8").Value
If Trim(Num) <> "" Then
Set c = .Range("A:A").Find(Num, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
If MsgBox("Voulez-vous supprimer la commande " & Num & "?", vbYesNo + vbDefaultButton2 + vbExclamation) = vbNo Then Exit Sub
c.EntireRow.Delete
Set c = Nothing
End If
End If
End With
LaLigne = 0
End Sub |
Partager