Word macro to run in Outlook

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

Word macro to run in Outlook

Post by Rudi »

Hi,

Hans helped me with this macro to add a standard border and shadow to a selected picture. I am successfully running it in Word 2010, but now want to run it in Outlook too. I thought I could copy the macro into a module in Outlook, but it does not run. Can anyone assist with how to get it to run on a selected picture in a new email message.

TX

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
Regards,
Rudi

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

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

Re: Word macro to run in Outlook

Post by HansV »

You have to set up editing the emal message as a Word document:

Code: Select all

Sub FormatPicture()
    Dim p As Object
    If TypeName(ActiveWindow) = "Inspector" Then
        If Not ActiveInspector.CurrentItem.Class = olMail Then
            MsgBox "This item is not an e-mail message.", vbExclamation
            Exit Sub
        End If
    Else
        MsgBox "Please open an e-mail message and select a shape in it.", vbExclamation
        Exit Sub
    End If
    With ActiveInspector.WordEditor.Application
        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
    End With
    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
Best wishes,
Hans

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

Re: Word macro to run in Outlook

Post by Rudi »

Thanks Hans,

Can you confirm my steps:
In Outlook I press Alt + F11
I insert a new module
I paste the code you supplied
I open a new message and insert a picture in the body
Select the picture and run the macro from a button on my Quick Access Toolbar

When I click the button...nothing happens???
Regards,
Rudi

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

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

Re: Word macro to run in Outlook

Post by HansV »

Perhaps macros have been disabled? I tested the code and it worked OK for me.

What happens if you select the picture, then switch to the Visual Basic Editor, click in the macro and press F8 to single-step through it?
Best wishes,
Hans

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

Re: Word macro to run in Outlook

Post by Rudi »

Blush

As you rightly assumed: Macros were disabled!
Many TX!
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

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