PDA

View Full Version : Apply Artistic Effect to Current Selection / Create Button



Sir Phoenix
09-13-2011, 05:33 AM
Hello everyone,

I'm trying to achieve a couple things that are related:

Main issue:
I want to write code so that when this function is run, the currently selected picture will have an artistic effect applied. This is the code I've tried to write for it, but I cannot get it to work. Note, this is not intended to be used during presentation mode, but normal mode.

Sub EdgeDefine()
Dim myShape As Shape
Dim myEffect As PictureEffect

If ActiveWindow.Selection.Type = ppSelectionShapes Then
Set myShape = ActiveWindow.Selection
With myShape.Fill.PictureEffects
If .Count > 0 Then
.Delete (1)
Else
.Insert (msoEffectGlowEdges)
End If
End With
End If
End Sub


My second problem (related), is I want to tie this macro to a custom button that I can put on the ribbon. What's the easiest/most efficient way how to accomplish this?

John Wilson
09-13-2011, 08:35 AM
Sub EdgeDefine()
Dim myShape As Shape
Dim myEffect As PictureEffect

If ActiveWindow.Selection.Type = ppSelectionShapes Then
Set myShape = ActiveWindow.Selection.ShapeRange(1)
If myShape.Type = msoPicture Then
With myShape.Fill.PictureEffects
If .Count > 0 Then
.Delete (1)
Else
.Insert (msoEffectGlowEdges)
End If
End With
End If
End If
End Sub

To add a custom button to the ribbon you should use XML
There's a tutorial on the basics here (http://www.pptalchemy.co.uk/custom_UI.html)

Sir Phoenix
09-13-2011, 08:52 AM
John,

Thank you! It's frustrating that it only needed a slight change, but Powerpoint coding is fairly new to me. You rock!

John Wilson
09-13-2011, 09:14 AM
Download this (http://www.pptalchemy.co.uk/edge.pptm)

Insert and select a Picture and look in Picture Tools Tab
One advantage of using the Picture Tools tab is it will only show when a picture is selected.

Sir Phoenix
09-13-2011, 10:36 AM
Bah.

It works....

But only on some images. Is there anything I can do to tell it to do any image, or how I can check the properties of my images so I can recode to check for it?

Sir Phoenix
09-13-2011, 10:43 AM
To add additional information, I tried to copy two photos to my macro-enabled ppt so I could put a watch on the code.

When I copied them over, code worked on both.
Pre-copy, only one worked.

????

John Wilson
09-14-2011, 06:16 AM
You are probably running into one of the little tests that 2007 on programmers built in to annoy you.

If you have a picture in a placeholder 2007 thinks that the placeholder is the shape and therefor it's not a picture!

You would need to query the contained type

Sub EdgeDefine()
Dim myShape As Shape
Dim myEffect As PictureEffect

If ActiveWindow.Selection.Type = ppSelectionShapes Then
Set myShape = ActiveWindow.Selection.ShapeRange(1)
If myShape.Type = msoPlaceholder Then
If myShape.PlaceholderFormat.ContainedType = msoPicture Then
With myShape.Fill.PictureEffects
If .Count > 0 Then
.Delete (1)
Else
.Insert (msoEffectGlowEdges)
End If
End With
End If
End If
If myShape.Type = msoPicture Then
With myShape.Fill.PictureEffects
If .Count > 0 Then
.Delete (1)
Else
.Insert (msoEffectGlowEdges)
End If
End With
End If
End If
End Sub


If you use the example I uploaded you can delete all of the checks because if the Picture tools shows it IS a picture.

Sir Phoenix
09-14-2011, 07:17 AM
I solved this. Basically, if you skip the validation of what kind of shape it is, and just try to apply the pictureeffect, then it will do it to every picture. My guess is that pasting a shape into a powerpoint inserts it as an image.

Thank you to all who helped!

John Wilson
09-14-2011, 08:54 AM
My guess is that you are copying a picture in a placeholder and pasting it outside.

Paul_Hossler
09-14-2011, 10:29 AM
You are probably running into one of the little tests that 2007 on programmers built in to annoy you


:thumb

You must have cracked the code

Paul