0

I use Word 2013 content controls that are mapped to an XML data source. Some of them are inside repeating sections mapped to XML elements.

The problem is with 'Picture' content controls. When I switch to 'Design mode' and then back to normal, all picture content controls are changing the sizes of their pictures to something like 5 cm. After that I have to set all those pictures' width. But these settings are being reset after another entering to 'Design mode'.

What I want is that all pictures in these content controls are having width = 100% of a page text width. How can I make it?

I tried to attach images, but

3
  • ... I tried to attach images but cannot do it because my reputation is less than 10, unfortunately.
    – Anton
    Nov 26, 2013 at 18:20
  • Picture layout is always 'In line with text'. All pictures are inside their own paragraphs aligned in center.
    – Anton
    Nov 26, 2013 at 18:33
  • So far, I found this solution: VB Macro, that sets all inline shapes width within the selected text.
    – Anton
    Nov 26, 2013 at 19:48

1 Answer 1

0

I created this macro that within selected text sets all inline pictures widths to some predefined value (16.5 cm in my case). It looks more like a workaround than a real solution because each time after entering 'Design mode' I have to select all images (other content may also be selected, it remains untouched) within repeating sections and run this macro. Anyway, it is better than nothing.

  Sub ResizeImage()
    Dim targetWidth As Single
    Dim oILShp As InlineShape

    targetWidth = 16.5

    For Each oILShp In Selection.InlineShapes
        With oILShp
            .Height = AspectHt(.Width, .Height, CentimetersToPoints(targetWidth))
            .Width = CentimetersToPoints(targetWidth)
        End With
    Next
End Sub
Private Function AspectHt(ByVal origWd As Single, ByVal origHt As Single, ByVal newWd As Single) As Single
    If origWd <> 0 Then
        AspectHt = origHt / origWd * newWd
    Else
        AspectHt = 0
    End If
End Function

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .