如何将徽标图像集中到Word 2016页脚中?

发布于 2025-01-31 19:08:53 字数 1328 浏览 2 评论 0原文

我想将徽标图像集中在Word 2016文档的页脚中。

基于 word footer image image图像对齐,我可以得到徽标进入页脚,但无法将其居中。

Sub Main()
'Based on https://stackoverflow.com/questions/58257052/word-footer-image-alignment-in-vba
  Dim FIRMADOC As String
  Dim SHP As InlineShape
  Dim rng As Word.Range

  FIRMADOC = "C:\Users\" & Environ("username") & "\Documents\Invoice\footer.png"

  Set rng = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
  rng.Collapse wdCollapseStart
  rng.Text = vbTab & vbTab 'position at second, right-aligned tab in the footer)
    ‘(Note: I have tried removing the tabs to no useful effect)
  Set SHP = rng.InlineShapes.AddPicture(FileName:=FIRMADOC, LinkToFile:=False, SaveWithDocument:=True, Range:=rng)
  
'Based on Record Macro
      ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Application.Templates( _
        "C:\Users\Brian\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Built-In Building Blocks.dotx" _
        ).BuildingBlockEntries("Bold Numbers 3").Insert Where:=Selection.Range, _
        RichText:=True
End Sub

图像(“ FirmAdoc”)结束时是合理的。手动更改家庭标签的对齐工作。记录手动更改空无一人。

I want to center a logo image in the footer of a Word 2016 document.

Based on code from Word footer image alignment in VBA, I can get the logo into the footer but cannot get it centered.

Sub Main()
'Based on https://stackoverflow.com/questions/58257052/word-footer-image-alignment-in-vba
  Dim FIRMADOC As String
  Dim SHP As InlineShape
  Dim rng As Word.Range

  FIRMADOC = "C:\Users\" & Environ("username") & "\Documents\Invoice\footer.png"

  Set rng = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
  rng.Collapse wdCollapseStart
  rng.Text = vbTab & vbTab 'position at second, right-aligned tab in the footer)
    ‘(Note: I have tried removing the tabs to no useful effect)
  Set SHP = rng.InlineShapes.AddPicture(FileName:=FIRMADOC, LinkToFile:=False, SaveWithDocument:=True, Range:=rng)
  
'Based on Record Macro
      ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Application.Templates( _
        "C:\Users\Brian\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Built-In Building Blocks.dotx" _
        ).BuildingBlockEntries("Bold Numbers 3").Insert Where:=Selection.Range, _
        RichText:=True
End Sub

The image ('FIRMADOC') ends up left justified. Manually changing alignment from Home Tab works. Recording that manual change comes up empty.

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

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

发布评论

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

评论(1

離人涙 2025-02-07 19:08:53

例如:

Dim Shp As Shape
With ActiveDocument
    Set Shp = .Shapes.AddPicture(FileName:="C:\Users\" & Environ("username") & "\Documents\Invoice\footer.png", _
        LinkToFile:=False, SaveWithDocument:=True, Anchor:=.Sections(1).Footers(wdHeaderFooterPrimary).Range)
    Shp.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
    Shp.Left = wdShapeCenter
End With

或者,如果您希望将徽标格式化为在线:

With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
    .InlineShapes.AddPicture FileName:="C:\Users\" & Environ("username") & "\Documents\Invoice\footer.png", _
        LinkToFile:=False, SaveWithDocument:=True, Range:=.Characters.Last
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
End With

For example:

Dim Shp As Shape
With ActiveDocument
    Set Shp = .Shapes.AddPicture(FileName:="C:\Users\" & Environ("username") & "\Documents\Invoice\footer.png", _
        LinkToFile:=False, SaveWithDocument:=True, Anchor:=.Sections(1).Footers(wdHeaderFooterPrimary).Range)
    Shp.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
    Shp.Left = wdShapeCenter
End With

or, if you want the logo formatted as in-line:

With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
    .InlineShapes.AddPicture FileName:="C:\Users\" & Environ("username") & "\Documents\Invoice\footer.png", _
        LinkToFile:=False, SaveWithDocument:=True, Range:=.Characters.Last
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文