Option Explicit
Public mode As String
Public document As String
Private Sub UserForm_Activate()
Dim rname$, t
If document = "facture" Then rname = "tsauvegardeF" Else rname = "tsauvegardeD"
If mode = "pdf" Then
BtImprim.Caption = "en pdf"
Titre.Caption = "faire un PDF " & document
Else
Titre.Caption = "ré Imprimer " & document
BtImprim.Caption = "Imprimmer"
End If
t = Range(rname).Value
With Me.liste
.ColumnCount = 10 ' UBound(t, 2)
.ColumnWidths = "70;70;70;70;0;0;0;0;0;0;0;0;0"
If UBound(t) = 1 Then liste.Column = Application.Transpose(t) Else liste.List = t
End With
End Sub
Private Sub BtClose_Click(): Unload Me: End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
clearPageDevis
ClearPageFacture
End Sub
Private Sub BtImprim_Click()
Dim t, plage As Range, col, cel As Range, F As Worksheet, I&
With liste
If .ListIndex = -1 Then Exit Sub
t = Application.Index(.List, .ListIndex + 1, 0)
End With
If document = "devis" Then Set F = Feuil3 Else Set F = Feuil4
Set plage = F.[H3,K7,L10,j13,j16,A21,M21,A22,M22,A23,M23]
col = Array(0, 4, 1, 3, 7, 2, 8, 9, 10, 11, 12, 13)
For Each cel In plage
I = I + 1
If LCase(Replace(t(col(I)), "€", "")) Like "*[A-z|/]*" Or t(col(I)) = "" Then cel.Value = CStr(t(col(I))) Else cel = CDbl(t(col(I)))
Next
Feuil3.Calculate
Feuil4.Calculate
If mode <> "pdf" Then
F.PrintOut
Else
If document = "devis" Then createdevisPDF Else CreateFacturePDF
End If
mode = "": document = ""
End Sub