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
| Option Explicit
Function NomDocument(ByVal LeNom As String, LePrenom As String) As String
Dim I As Integer
Dim NouveauNom As String, NouveauPrenom As String
For I = 1 To Len(Trim(LeNom))
Select Case Mid(Trim(LeNom), I, 1)
Case Chr(10), Chr(13)
Case Else
NouveauNom = NouveauNom & Mid(Trim(LeNom), I, 1)
End Select
Next I
For I = 1 To Len(Trim(LePrenom))
Select Case Mid(Trim(LePrenom), I, 1)
Case Chr(10), Chr(13)
Case Else
NouveauPrenom = NouveauPrenom & Mid(Trim(LePrenom), I, 1)
End Select
Next I
NomDocument = UCase(NouveauNom) & " " & UCase(Mid(NouveauPrenom, 1, 1)) & LCase(Mid(NouveauPrenom, 2, Len(NouveauPrenom) - 1)) & " " _
& Format(Year(Date), "0000") & "-" & Format(Month(Date), "00") & "-" & Format(Day(Date), "00")
End Function
Sub SauvegardeDoc()
Dim Repertoire As String
Repertoire = "D:\XXXX\" ' A adapter
With ActiveDocument
If .Bookmarks.Exists("Nom") And .Bookmarks.Exists("Prénom") Then
'MsgBox NomDocument(.Bookmarks("Nom").Range.Text, .Bookmarks("Prénom").Range.Text)
.SaveAs2 FileName:=Repertoire & NomDocument(.Bookmarks("Nom").Range.Text, .Bookmarks("Prénom").Range.Text), fileformat:=wdFormatXMLDocument
End If
End With
End Sub |
Partager