Iban Arriola
Iban Arriola

Reputation: 2796

get format of image and videos in visual basic

I have some images and videos in my powerpoint presentation. Depends of what format have each one (jpg, mp3, jpeg,...) I want it to make a different thing so I need to know what kind of file is it. Is there anything in Visual Basic to make it?

EDITED

I want to difference the images and videos supported by iPad with the ones that are not supported. That is why I need to know the format of them.

Upvotes: 0

Views: 1269

Answers (2)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

As has been pointed out, you can get the file types for linked files, but there's no way to get them for embedded files. However, if you don't need to do it in VBA or can manipulate ZIP files in VBA, open the PPTX as a zip and look for the media folder. There you'll find any embedded files (pictures, sounds, movies).

They may not be in the same format as they originally were in; PPT sometimes converts images when it imports them. But that shouldn't be an issue considering what you're after.

Upvotes: 1

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19077

EDIT: to state it clear- solution below works only with shapes which are linked to files!

Function WhatTypeOfMedia(SHP As Shape)

    Select Case Right(SHP.LinkFormat.SourceFullName, 4)
        Case ".jpg", "jpeg"
            WhatTypeOfMedia = "Picture type"
        Case ".wav", ".mp3"
            WhatTypeOfMedia = "Music type"
        '... end other possible types put here
    End Select
End Function

To make a test run for 1st slide of active presentation try this code:

Sub Take_format_Linked()

    On Error Resume Next    'required for these files which are not linked
    Dim SHP As Shape
    For Each SHP In ActivePresentation.Slides(1).Shapes
    '1st check if format is linked- best option:
    If Len(SHP.LinkFormat.SourceFullName) > 0 Then
        If Err.Number = 0 Then
        'if so, let's call function
            Debug.Print WhatTypeOfMedia(SHP)
        'here you can do what you want based on function result
        Else
            Err.Clear
        End If
    End If
    Next

End Sub

As a result you get information in Immediate window which shape is which type. You could use that types to run what you need in main sub. In that simple idea I kept On Error Resume Next to avoid error if Shape is not linked.

Upvotes: 1

Related Questions