![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
|||
|
|||
|
hi all,
i tried asking for a solution to this problem a while ago on the mail merge forum but after reading about this for quite a while i think the only choice is to use a macro after the merge, https://www.msofficeforums.com/mail-...html#post77641 Essentially i need to include conditional full page letter head in my mail merge. i have formatted the letterhead to by A4 in size but whenever i run the merge with this field code, {INCLUDEPICTURE ".../pictures/Logos/{MERGEFIELD "internal_party" }.jpg \*MERGEFORMAT \d } , the picture shinks within the margin ( i believe this is because merged pictures are in line with text). Therefore i think i need a macro that selects the merged picture, sets the text wrapping to behind text, and then scale to 100%. Code:
Sub fixLetterHead()
Dim shape As InlineShape
Dim shapeRange As shapeRange
' iterate all selected shapes
For Each shape In Selection.InlineShapes
' set with to 100 %
shape.ScaleWidth = 100
' convert to shape to get a shaperange
shape.ConvertToShape
Set shapeRange = Selection.shapeRange
' position relative to the page
shapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
shapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionPage
' anchor to 0.0
shapeRange.Top = 0
shapeRange.Left = 0
' set to behind text
shapeRange.WrapFormat.Type = wdWrapBehind
Next
If Selection.InlineShapes.Count > 0 Then
Selection.InlineShapes(1).ScaleHeight = 100
Selection.InlineShapes(1).ScaleWidth = 100
Else
Selection.shapeRange.ScaleHeight Factor:=100, _
RelativeToOriginalSize:=msoCTrue
Selection.shapeRange.ScaleWidth Factor:=100, _
RelativeToOriginalSize:=msoCTrue
Selection.shapeRange.WrapFormat.Type = wdWrapBehind
End If
End Sub
ive pieced the above code together from online forums but its not working correctly. Also it only runs on selected pictures but i need to have it run for th eonly picture in the document. the picture does correctly become behind text but it doesnt scale to 100%. Am i close to having this working? if so, can someone please let me know how to amend my code? unfortunately i cant record macros to do this because word does not allow you to for pictures. or if anyone has any other suggested solutions im all ears. Whatever the solution is it needs to be completely automatic. Thank you in advance for any help. |
|
#2
|
||||
|
||||
|
Once you change an inline shape to a shape it is no longer an inline shape so you cannot process it as such. The following should work
Code:
Sub fixLetterHead()
Dim oInlineShape As InlineShape
Dim oShape As shape
For Each oInlineShape In Selection.InlineShapes
Set oShape = oInlineShape.ConvertToShape
With oShape
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Top = 0
.Left = 0
.WrapFormat.Type = wdWrapBehind
.ScaleHeight 1, True
.ScaleWidth 1, True
End With
Next oInlineShape
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thank you very much! this works perfectly. i have amended it slightly by having a Exit For statement at the end of the for loop to only convert the first picture it finds. probably not the best way to do it but it works well so far.
Thank you |
|
#4
|
||||
|
||||
|
Exit For will do the job or you could lose the loop and change to
Code:
Set oInlineShape = Selection.InlineShapes(1)
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
| Tags |
| formatting, picture |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Using IncludePicture and MailMerge to insert picture
|
Elena | Mail Merge | 25 | 02-06-2022 05:35 PM |
| Microsoft Word macro to find text, select all text between brackets, and delete | helal1990 | Word VBA | 4 | 02-05-2015 03:52 PM |
VBA code for Microsoft Word macro — select text and insert footnote
|
ndnd | Word VBA | 10 | 01-06-2015 01:47 PM |
Is it possible to not select all text upon entering a form field?
|
pruppert | Word | 6 | 07-16-2012 08:01 PM |
| Word Editing Text for Picture format | sarun5 | Word | 2 | 05-27-2009 11:51 PM |