1
votes

Having trouble getting access vba to set a word document's header properly. I've got this.

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!"

What happens right now is the text will replace the picture for the first page (subsequent pages are fine).

I need to have the picture and text - and I need to offset the picture to the left about half an inch while text is centered with normal margins.

Any idea how to go about it? Basically I need to set a document letterhead with a logo.

Update

Dim myText As String myText = "hello there"

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

I've got half of it done, now I just need to position the image to -.5 to margin.

Completed Solution

Just add "Left:=-35" to the picture like such (or whatever value works)

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

2 Answers

0
votes

Have you tried recording a macro in Word that does the rough reposition - then bring the code over to Access and edit it for the correct object and size?

0
votes

All of it is updated in the original thread. it took using the .Range Collapse to add in text along with the image and it took putting Left:=(value) to move it where I needed it.