PDA

View Full Version : Solved: What's an Enhanced Metafile called in VBA?



owen_1987
08-09-2011, 04:20 AM
Hi all,

I'm new here and just wanted to ask what I hope is a straight forward question. When refering to an Enhanced Metafile object, what is the correct name for it?

The context of the question is that I am writing a macro to resize and centralise all of the Enhanced Metafile objects in my presentation. But at the moment the code is refering to "picture" (txt in red) which is resizing and centralising every picture on the slides. All of the pictures are jpeg's which is why I am trying to distinguish from the Enhanced Metafiles.

My code:

Sub picturesizer()

Dim i As Integer
Dim osld As Slide
Dim opic As ShapeRange
For Each osld In ActivePresentation.Slides
For i = 1 To osld.Shapes.Count

If osld.Shapes(i).Type = msoPicture Then
Set opic = osld.Shapes.Range(i)
opic.LockAspectRatio = True
opic.Height = 320 'change to suit
opic.Align msoAlignMiddles, msoTrue
opic.Align msoAlignCenters, msoTrue
End If
Next i
Next osld
End Sub



Hope that makes sense and thanks in advance for any help/ advice

owen_1987
08-09-2011, 04:22 AM
I forgot to say that I am using PowerPoint 2007 (if that makes any difference)

John Wilson
08-09-2011, 09:45 AM
To the best of my knowledge there's no way to detect emf in vba. In 2007 this may work (It won't in 2010)

If UCase(Right(osld.Shapes(i).AlternativeText, 3)) = "EMF" Then

owen_1987
08-10-2011, 01:15 AM
Thanks for your help John, unfortuantly it doesn't work so from what you are saying I don't think I can do it this way.

Is there a different way I can go about this with the same result?

John Wilson
08-10-2011, 04:34 AM
Usually in 2007 the Alternative text is set to the filename so it would usually work. Have you manually checked the Alt Text (RIGHT click > Size & Position > Alt Text)

AFAIK once embedded PowerPoint sees all pictures as just pictures (not EMF or JPG) The only other test I can think of is to set On Error Resume Next >> ungroup - if you get an error code it wasn't an EMF. Not good but might work.

owen_1987
08-10-2011, 04:59 AM
Thanks very much John.

I'm sorry I am pretty new to vba (so thanks for baring with me) and after some research about Alt text I understand the code you wrote. My Alt text was blank so after writing "EMF" in all of the pictures it now works.

So as I understand it, the "EMF" is a tag on the pictures so i'm telling the macro to look for the Alt text in a "shape" rather than just any type of "picture".

John Wilson
08-10-2011, 07:05 AM
When you add a picture to 2007 it usually writes the file name into the alt text. Add a new pic and see. If it's an EMF the file name would end with .EMF

This doesn't happen in 2010 and probably not in 2003

If it's blank then it's not going to help!

pptools
08-11-2011, 05:40 PM
You can at least distinguish images from vector graphics by attempting to ungroup them. If it throws an error, it's likely an image. Trap the error and stop trying. Otherwise, it ungrouped.

owen_1987
08-16-2011, 05:37 AM
John's method did exactly what I wanted it to do after understanding it properly. Thanks everyone else that also commented