Macro to format a picture

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Macro to format a picture

Post by Rudi »

Hi,

I noticed that Word 2010 does not record the actions to add a picture style and border weight to selected pictures. I was wondering if anyone can assist me in creating a macro that does two things:

Assuming the picture is already selected...
1. Assigns the picture style called: Simple frame black
2. Assigns a picture border with a line weight of 1pt to the picture

Thats it. It's weird that this does not get recorded, but any assistance will be greatly appreciated. TX.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78492
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro to format a picture

Post by HansV »

Is it an inline picture or a floating picture?
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Macro to format a picture

Post by Rudi »

Both. Most are wrapped around text and some are inline. However, the picture will always be selected before i run the macro.
TX
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78492
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro to format a picture

Post by HansV »

Try this:

Code: Select all

Sub FormatPicture()
    Dim p As Object
    If Selection.InlineShapes.Count = 1 Then
        Set p = Selection.InlineShapes(1)
    ElseIf Selection.ShapeRange.Count = 1 Then
        Set p = Selection.ShapeRange(1)
    Else
        MsgBox "Please select a single shape or inline shape.", vbExclamation
        Exit Sub
    End If
    With p.Shadow
        .Blur = 4
        .OffsetX = 3
        .OffsetY = 3
        .Size = 100
        .Style = msoShadowStyleOuterShadow
        .Transparency = 0.57
        .Visible = True
    End With
    With p.Line
        .Weight = 1
        .ForeColor = vbBlack
    End With
End Sub
It should work with both inline shapes and floating shapes.
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Macro to format a picture

Post by Rudi »

Awesome. Hans....Thank you for the time and effort. I really do appreciate it.
Big Cheers!!!!
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.