【问题标题】:VBA - Update Headers Fields to Word From ExcelVBA - 从 Excel 将标题字段更新为 Word
【发布时间】:2021-04-22 05:57:51
【问题描述】:

从 excel 导出数据后,我尝试更新 word 文档中的标题字段。

这是我正在尝试的:

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

但是更新没有任何反应,我的字段链接在一个书签上,该书签使用我的脚本进行了更新。

有人可以帮我吗?

非常感谢你,Lyrha。

【问题讨论】:

标签: excel vba ms-word


【解决方案1】:

例如:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    相关资源
    最近更新 更多