【发布时间】: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
【问题讨论】: