Reputation: 11
I try to update headers fields in my word document after export datas from excel.
Here is what I am trying:
Dim wd As Word.Application
Dim wdDoc As Word.Document
Set wd = New Word.Application
Set wdDoc = wd.Documents.Open(ThisWorkbook.Path & "\Template_rapportfusion.docx ")
[... my code for export data ...]
'Update fields
wdDoc.Fields.Update
'Save the document
wdDoc.SaveAs2 (ThisWorkbook.Path & "\" & QuestionSheet.Range("Nom_Organisme") & "-" & QuestionSheet.Range("Date").Value & ".docx")
'Close the document
wdDoc.Close
wd.Quit
But nothing happens on the update, my fields are linked on a bookmark who is updated whith my script.
Can somebody help me ?
Thank you very much, Lyrha.
Upvotes: 0
Views: 178
Reputation: 13490
For example:
With wdDoc
'Update fields
.Fields.Update
.PrintPreview
.ClosePrintPreview
'Save the document
.SaveAs2 (ThisWorkbook.Path & "\" & QuestionSheet.Range("Nom_Organisme") & "-" & QuestionSheet.Range("Date").Value & ".docx")
'Close the document
.Close False
End With
Upvotes: 1