VBA word - Création document à partir de bookmarks
Bonjour a tous,
Je commence tout juste le VBA.
J'aimerais avoir la possibilité de créer un document word en cochant des checkbox dans un userForm qui, si elles sont cochés vont récupérer le bookmark dans un autre document word pour l’insérer dans un bookmark de mon document actif.
Pour ça, j'ai utilisé la propriété Text de Range seulement lors de la copie je ne conserve pas le format ni les tableau.
Code:
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
| Dim oTarDoc As Document, oSourceDoc As Document
Dim CheminCommonInformations As String
Dim CheminRegulation As String
Dim oRng As Word.Range
Private Sub GenerateButton1_Click()
ActiveDocument.Paragraphs.LineSpacingRule = wdLineSpaceSingle
Set oTarDoc = ActiveDocument
If CommonInformations.Value = True Then
CheminCommonInformations = "C:\...\Common Informations.docx"
Set oSourceDoc = Documents.Open(CheminCommonInformations)
With oTarDoc
'se positionne au bookmark CommonInformation dans le template
Set oRng = .Bookmarks("CommonInformations").Range
'Récupère le texte du bookmark All du fichier source
oRng.text = oSourceDoc.Bookmarks("All").Range.text
'Ajoute le texte au bookmark du document actif
.Bookmarks.Add "CommonInformations", oRng
End With
oSourceDoc.Close
End If |
Je ne sais pas si je procède de la bonne facon.
Merci de votre aide