【问题标题】:Access VBA Create Word header with text and position picture访问 VBA 创建带有文本和位置图片的 Word 标题
【发布时间】:2020-07-13 20:05:46
【问题描述】:

无法访问 vba 以正确设置 word 文档的标题。我有这个。

oDoc.PageSetup.DifferentFirstPageHeaderFooter = True  
oDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Range.InlineShapes.AddPicture "C:\Users\mr.helpless\Pictures\doody.jpg"
oDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Text = "hello there"
oDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "whooo hooo!"

现在发生的是文本将替换第一页的图片(后续页面都可以)。

我需要图片和文本 - 我需要将图片向左偏移大约半英寸,同时文本以正常边距居中。

知道怎么做吗?基本上我需要设置一个带有徽标的文档信头。

更新

将 myText 调暗为字符串 myText = "你好"

With oDoc.Sections(1).Headers(wdHeaderFooterFirstPage)
  .Shapes.AddPicture Filename:="C:\Users\mr.helpless\Pictures\doody.jpg", LinkToFile:=False, SaveWithDocument:=True
  .Range.Collapse
  .Range.InsertAfter (myText)
  .Range.Font.Name = "Helvetica"
  .Range.Font.Size = 8
  .Range.Font.Bold = True
  .Range.Paragraphs.Alignment = wdAlignParagraphCenter
End With

我已经完成了一半,现在我只需要将图像定位到 -.5 到边距。

完成的解决方案

只需像这样在图片中添加“Left:=-35”(或任何有效的值)

.Shapes.AddPicture Filename:="C:\Users\mr.helpless\Pictures\doody.jpg", LinkToFile:=False, SaveWithDocument:=True, Left:=-35

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    您是否尝试过在 Word 中录制一个宏来进行粗略的重新定位 - 然后将代码带到 Access 并编辑它以获得正确的对象和大小?

    【讨论】:

    • 是的,由于某种原因,重新定位不会记录 - 但我想通了。
    【解决方案2】:

    所有这些都在原始线程中更新。它需要使用 .Range Collapse 将文本与图像一起添加,并且需要将 Left:=(value) 移动到我需要的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      相关资源
      最近更新 更多