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
|
'---------------------------------------------------------------------------------------
' Procédure : AddMyVar [Function]
' Retour : Boolean
' Version : 1.0
' Création/Maj : Le samedi 12 janvier 2008
' Objet : Ajouter une variable
' : Si la variable existe et bUpdateIfExists = true :
' : => Mise à jour de sa valeur
' Historique :
'---------------------------------------------------------------------------------------
Public Function AddMyVar(ByVal sNom As String, ByVal sText As String, _
Optional bUpdateIfExists As Boolean = True) As Boolean
On Error Resume Next
ActiveDocument.Variables.Add sNom, sText
If err = 5903 Then 'La variable existe déjà
If bUpdateIfExists Then
err.Clear
ActiveDocument.Variables(sNom).Value = sText
End If
End If
If err = 0 Then AddMyVar = True
End Function
'---------------------------------------------------------------------------------------
' Procédure : LetMyVar [Function]
' Retour : Boolean
' Version : 1.0
' Création/Maj : Le samedi 12 janvier 2008
' Objet : Mettre à jour une variable
' : Si la variable n'existe pas et bAddIfNotExists = True :
' : => Ajoute la variable
' Historique :
'---------------------------------------------------------------------------------------
Public Function LetMyVar(ByVal sNom As String, ByVal sText As String, _
Optional bAddIfNotExists As Boolean = True) As Boolean
On Error Resume Next
Dim lIdx As Long
lIdx = ActiveDocument.Variables(sNom).Index
If err = 0 Then
ActiveDocument.Variables(lIdx).Value = sText
ElseIf err = 5825 Then 'La variable n'existe pas
If bAddIfNotExists Then
err.Clear
ActiveDocument.Variables.Add sNom, sText
End If
End If
If err = 0 Then LetMyVar = True
End Function
'---------------------------------------------------------------------------------------
' Procédure : IsMyVar [Function]
' Retour : Boolean
' Version : 1.0
' Création/Maj : Le samedi 12 janvier 2008
' Objet : Vérifier si une variable existe ou non
' : Argument : Index ou Nom de la variable
' Historique :
'---------------------------------------------------------------------------------------
Public Function IsMyVar(ByVal vItem As Variant) As Boolean
On Error Resume Next
IsMyVar = (ActiveDocument.Variables(vItem).Index > 0)
If err = 5825 Then err.Clear 'La variable n'existe pas
End Function
'---------------------------------------------------------------------------------------
' Procédure : DelMyVar [Function]
' Retour : Boolean
' Version : 1.0
' Création/Maj : Le samedi 12 janvier 2008
' Objet : Supprime une variable par son nom ou son index
' Historique :
'---------------------------------------------------------------------------------------
Public Function DelMyVar(ByVal vItem As Variant) As Boolean
On Error Resume Next
ActiveDocument.Variables(vItem).Delete
If err = 0 Then
DelMyVar = True
Else
err.Clear
End If
End Function
'---------------------------------------------------------------------------------------
' Procédure : DelAllMyVars [Function]
' Retour : Boolean
' Version : 1.0
' Création/Maj : Le samedi 12 janvier 2008
' Objet : Supprimer toutes les variables
' Historique :
'---------------------------------------------------------------------------------------
Public Function DelAllMyVars() As Boolean
On Error GoTo errtag
While ActiveDocument.Variables.Count
ActiveDocument.Variables(1).Delete
Wend
DelAllMyVars = True
Exit Function
errtag:
MsgBox "L'erreur n°" & err & " est survenue...", vbExclamation, "DelAllMyVars()"
Resume Next
End Function
'---------------------------------------------------------------------------------------
' Procédure : GetValueMyVar [Function]
' Retour : String
' Version : 1.0
' Création/Maj : Le samedi 12 janvier 2008
' Objet : Récupérer le contenu de la variable par son nom ou son index
' : Si elle n'existe pas, retourne la valeur par défaut ou une chaine vide
' Historique :
'---------------------------------------------------------------------------------------
Private Function GetValueMyVar(ByVal vItem As Variant, _
Optional ByVal sDefaut As String) As String
On Error Resume Next
GetValueMyVar = ActiveDocument.Variables(vItem).Value
If err Then
If err = 5825 Then err.Clear
GetValueMyVar = sDefaut
End If
End Function
'---------------------------------------------------------------------------------------
' Procédure : GetIndexMyVar [Function]
' Retour : Long
' Version : 1.0
' Création/Maj : Le samedi 12 janvier 2008
' Objet : Récupérer l'index de la variable par son nom
' Historique :
'---------------------------------------------------------------------------------------
Public Function GetIndexMyVar(ByVal sNom As String) As Long
On Error Resume Next
GetIndexMyVar = ActiveDocument.Variables(sNom).Index
If err = 5825 Then err.Clear
End Function
'---------------------------------------------------------------------------------------
' Procédure : GetNomMyVar [Function]
' Retour : String
' Version : 1.0
' Création/Maj : Le samedi 12 janvier 2008
' Objet : Récupérer le nom de la variable par son index
' Historique :
'---------------------------------------------------------------------------------------
Public Function GetNomMyVar(ByVal lIndex As Long) As String
On Error Resume Next
GetNomMyVar = ActiveDocument.Variables(lIndex).Name
If err = 5825 Then err.Clear
End Function |
Partager