VBA Selection.InsertFile 在末尾另外添加 NewLine

发布于 2025-01-11 00:34:46 字数 1327 浏览 0 评论 0原文

我正在尝试使用以下代码导入一些Word文档作为页脚。不幸的是,selection.insertfile 函数会在页脚末尾另外插入一个新行。可以去掉吗?我尝试了很多事情,但没有结果。



Public Sub AutoOpen()

   'Fußzeile aktualisieren
    Call UpdateFooter
    
End Sub

'Fußzeile für alle Seiten editieren
Sub UpdateFooter()

    Application.ScreenUpdating = False
    
    Dim oDoc As Word.Document, oSec As Word.section, rng As Word.Range
    Set oDoc = ActiveDocument

    For Each oSec In oDoc.Sections
        Set rng = oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
        AddFooterToRange rng
        'oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Font.Size = 5
        
        Set rng = oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
        AddFooterToRange rng
        'oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Font.Size = 5
        
        Set rng = oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).Range
        AddFooterToRange rng
        'oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).Range.Font.Size = 5
        
    Next oSec
    
    Application.ScreenUpdating = True
    
End Sub

'Fußzeilendatei einfügen
Private Sub AddFooterToRange(rng As Word.Range)
    With rng
         .InsertFile "...fusszeile.docx"
    End With
End Sub

提前致谢。

I am trying to import some word documents as footer with the following code. Unfortunately, the selection.insertfile function inserts additionally a new line at the end of the footer. Is it possible to remove it? I've tried many things, without a result.



Public Sub AutoOpen()

   'Fußzeile aktualisieren
    Call UpdateFooter
    
End Sub

'Fußzeile für alle Seiten editieren
Sub UpdateFooter()

    Application.ScreenUpdating = False
    
    Dim oDoc As Word.Document, oSec As Word.section, rng As Word.Range
    Set oDoc = ActiveDocument

    For Each oSec In oDoc.Sections
        Set rng = oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
        AddFooterToRange rng
        'oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Font.Size = 5
        
        Set rng = oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
        AddFooterToRange rng
        'oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Font.Size = 5
        
        Set rng = oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).Range
        AddFooterToRange rng
        'oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).Range.Font.Size = 5
        
    Next oSec
    
    Application.ScreenUpdating = True
    
End Sub

'Fußzeilendatei einfügen
Private Sub AddFooterToRange(rng As Word.Range)
    With rng
         .InsertFile "...fusszeile.docx"
    End With
End Sub

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2025-01-18 00:34:46

您只需删除页脚中的最后一段即可。

Private Sub AddFooterToRange(rng As Word.Range)
    With rng
         .InsertFile "...fusszeile.docx"
         .Paragraphs.Last.Range.Delete
    End With
End Sub

You just need to delete the last paragraph in the footer.

Private Sub AddFooterToRange(rng As Word.Range)
    With rng
         .InsertFile "...fusszeile.docx"
         .Paragraphs.Last.Range.Delete
    End With
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文