# VBA code to centre pictures in WORD.



## S.H.A.D.O. (Apr 14, 2018)

Good afternoon,

I have the following code which works well at resizing *all* the pictures to a set size.
I can't however work out how to centre all the pictures at the same time though!


```
Sub Resize_Images1()
Dim i As Long
    With Application
        .ScreenUpdating = False: .DisplayAlerts = False
    End With
    With ActiveDocument
        For i = 1 To .InlineShapes.Count
            With .InlineShapes(i)
                .ScaleHeight = 40
                .ScaleWidth = 40
            End With
        Next i
    End With
    With Application
        .DisplayAlerts = True:  .ScreenUpdating = True
    End With
End Sub
```

Any help will be greatly appreciated.

Thanks in advance.


----------



## S.H.A.D.O. (Apr 14, 2018)

Not to worry, I have managed to create a workaround.
It appears that you can't centre a picture using VBA so you have to centre the paragraph (picture).
What I did was to create a further Sub and then called that from the Sub above.


----------



## Macropod (Apr 15, 2018)

After:
.ScaleWidth = 40
insert:
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter


----------



## S.H.A.D.O. (Apr 15, 2018)

Brilliant, thanks *Macropod*, it is very much apprciated.

Adding that single line to my existing code is far better than the solution I came up with which is this:


```
Sub Resize_Images()
Dim i As Long
    With Application
        .ScreenUpdating = False: .DisplayAlerts = False
    End With
    With ActiveDocument
        For i = 1 To .InlineShapes.Count
            With .InlineShapes(i)
                .ScaleHeight = 35
                .ScaleWidth = 35
            End With
        Next i
    End With
    Call Centre_Images
    With Application
        .DisplayAlerts = True: .ScreenUpdating = True
    End With
End Sub

Sub Centre_Images()
Dim j As InlineShape
    With Application
        .ScreenUpdating = False: .DisplayAlerts = False
    End With
    For Each j In ActiveDocument.InlineShapes
        If j.Type = wdInlineShapePicture Then
            j.Select
            Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
        End If
    Next j
    With Application
        .DisplayAlerts = True: .ScreenUpdating = True
    End With
End Sub
```

My code now is obviously this (I was almost there!):


```
Sub Resize_Images()
Dim i As Long
    With Application
        .ScreenUpdating = False: .DisplayAlerts = False
    End With
    With ActiveDocument
        For i = 1 To .InlineShapes.Count
            With .InlineShapes(i)
                .ScaleHeight = 35
                .ScaleWidth = 35
                .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            End With
        Next i
    End With
    With Application
        .DisplayAlerts = True: .ScreenUpdating = True
    End With
End Sub
```

Thanks again  .


----------

