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
| Dim oDoc As Word.Application
Dim wordDoc As Word.Document
Dim nFil As Long
Set oDoc = CreateObject("Word.Application")
oDoc.DisplayAlerts = wdAlertsNone
oDoc.WindowState = wdWindowStateMinimize
oDoc.Visible = True
Set wordDoc = oDoc.Documents.Open("D:\TEST.doc", False)
Call Filigranne("TEST FILIGRANE", oDoc)
wordDoc.Save
oDoc.Documents.Close False
oDoc.Quit False
Set wordDoc = Nothing
Set oDoc = Nothing
End Sub
'********************************
Sub Filigranne(Texte As String, doc As Word.Application)
Dim Section As Section
Dim Header As HeaderFooter
doc.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
For Each Section In ActiveDocument.Sections
For Each Header In Section.Headers
AddFiligranne Texte, Header, Section
Next
Next
Word.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
'******************************
Private Sub AddFiligranne(Texte As String, Header As HeaderFooter, Section As Section)
Dim ShapeName As String
Dim Shape As Variant
ShapeName = "Filigranne_" & Section.Index & "_" & Header.Index
Header.Range.Select
'détruit un éventuel filigranne précédent
On Error Resume Next
Set Shape = Header.Shapes(ShapeName)
If Not Shape Is Nothing Then Shape.Delete
If Texte = "" Then Exit Sub
'ajoute le filigranne (c'est dans l'entete, et ça prend 1x1 point en haut à gauche de la page)
Set Shape = Word.Selection.HeaderFooter.Shapes.AddTextEffect( _
Office.MsoPresetTextEffect.msoTextEffect1, _
Texte, "ARIAL", 1, False, False, _
0, 0)
Shape.Select
'met en forme le filigranne pour prendre toute la page
With Word.Selection.ShapeRange
.Name = ShapeName
.TextEffect.Text = Texte
.TextEffect.FontName = "Arial"
.TextEffect.FontSize = 1 'la taille de la police est fixé par le ratio
.Line.Visible = False
.Fill.Visible = True
.Fill.Solid
.Fill.ForeColor.RGB = WdColor.wdColorRed
.Fill.Transparency = 0.7
.Rotation = 305
.LockAspectRatio = True
.Height = CentimetersToPoints(3.22)
.Width = CentimetersToPoints(19.34)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeHorizontalPositionPage
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
End Sub |
Partager