|
本帖最后由 smorth 于 2023-5-23 17:28 编辑
求助一下各位大神。我想用excel的内容批量替换Word的内容,正文部分能正常替换,但是页眉部分没有被替换,网上找了各种资料,无果~
先上代码:
- 调用的函数:
- Private Function iRePlace(ByVal iFilePath As String, ByVal Content_Text As String, ByVal Replacement_Text As String)
- Dim MaFeuille As Worksheet
- Set MaFeuille = Sheets("项目表")
-
- Dim File As String
- ' File = ActiveWorkbook.Path & "" & "nomfichier.docx"
- Dim Word_APP As Object
- Set Word_APP = CreateObject("Word.Application")
- With Word_APP
- .Visible = True
- ' .WindowState = 1 'value for wdWindowStateMaximize
- End With
-
- Dim Word_Fichier As Object
-
- Set Word_Fichier = Word_APP.Documents.Open(iFilePath)
-
- With Word_Fichier.Range.Find
- .Text = Content_Text
- .Replacement.Text = Replacement_Text
- ' .Execute Replace:=2 'value for wdReplaceAll
-
- End With
-
-
-
- '=========================没有成功替换的部分=========================
- Dim Footr As Word.HeaderFooter
-
- For Each Footr In Word_Fichier.Sections(1).Footers
- With Footr.Range.Find
-
- .Text = "P-FCCD14O-01"
- .Replacement.Text = "P-TSPS01-01"
-
- .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindStop
-
- End With
-
- Next Footr
-
- '===============================================================
-
-
- Word_Fichier.Save
- Word_APP.Quit
-
-
- End Function
复制代码
|
|