Reputation: 2402
I am writing Word file from Excel using VBA. Current code is able to paste image to footer but it is pasted before texts that I have already in my footer. How to paste with parameters "In front of text"? Ideally I would like to have picture pasted to the most left corner in folder.
Here is my current code:
Dim SrcePath As String
SrcePath = "C:\Users\pc\Pictures\signature.png"
Dim t As Long
With WordDoc
For t = 1 To .Tables.Count
Set wdRng = .Tables(t).Range.Characters.Last.Next
If wdRng.End < .Range.End Then
If wdRng.Text = vbCr Then wdRng.Delete
End If
Next
.TablesOfContents(1).Update
.Sections(1).Footers(1).Range.InlineShapes.AddPicture (SrcePath)
End With
EDIT:
By in front of text I mean this option:
Upvotes: 0
Views: 883
Reputation: 13490
The problem is that:
.Sections(1).Footers(1).Range.InlineShapes.AddPicture (SrcePath)
inserts an InlineShape. You need to insert and position a floating Shape. For example:
Replace -
Dim t As Long
with:
Dim t As Long, Shp As Shape, sPosH As Single
Replace:
.Sections(1).Footers(1).Range.InlineShapes.AddPicture (SrcePath)
with:
With .Sections(1).PageSetup
sPosH = .PageWidth - .LeftMargin - .RightMargin - .Gutter
End With
Set Shp = .Sections(1).Footers(1).Shapes.AddPicture(SrcePath, False, True)
With Shp
.LockAspectRatio = True
.Width = Application.InchesToPoints(2)
.LeftRelative = 0 'wdRelativeHorizontalPositionMargin
.Left = sPosH - .Width
.TopRelative = 5 'wdRelativeVerticalPositionBottomMarginArea
.Top = 0
.WrapFormat.Type = 6 'wdWrapFront
End With
Note the 'Application.InchesToPoints(2)' line. That allows you to control the picture size via its width. There's a CentimetersToPoints property also, if you prefer.
Upvotes: 1