Consulting

Results 1 to 7 of 7

Thread: Check Word, Powerpoint and Excel files for embedded objects

  1. #1

    Check Word, Powerpoint and Excel files for embedded objects

    OS Environment: Windows XP
    MS Office: 2003

    At work we have the need to select a folder, traverse through the folder and subfolders opening files and determine if embedded objects exist. If embedded objects do exist then log that fact in a file and continue with the next file. The majority of the files consist of Word, Powerpoint and Excel. So I'm most concerned about those type files. I know how to traverse through the directory structure. But what I don't know is how to open the Word and Powerpoint files in an Excel macro and check for embedded objects. I'm using excel to host the macro because I'm most familiar with it. Any assistance would be greatly appreciated, thank you in advance.

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    For Word document, like this:[VBA] Dim appWord As Object
    Dim oWdDoc As Object
    Dim oleObj As Object
    Dim Shp As Object

    Const msoEmbeddedOLEObject As Long = 7

    Set appWord = CreateObject("Word.Application")

    Set oWdDoc = appWord.Documents.Open("<FullFileName>")

    For Each Shp In oWdDoc.Shapes
    If Shp.Type = msoEmbeddedOLEObject Then
    MsgBox "I'm here "
    End If
    Next Shp

    oWdDoc.Close False

    appWord.Quit
    Set appWord = Nothing[/VBA]
    Artik

  3. #3

    Thank you for the reply

    Artik,

    Wanted to thank you for your reply. I see that you test to see if the shape is equal to 7, which apparently is a certain type of shape. Where can I find the different types of objects to test for? Again thank you for your time, much appreciated.

    Steve

  4. #4
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Quote Originally Posted by bassnsjp
    Where can I find the different types of objects to test for?
    For example here.
    Or in Object Browser [F2] in VBE, search MsoShapeType Enumeration


    Artik

  5. #5

    Perfect..thank you so much

    Artik,

    Exactly what I needed to know, thank you very much. I wonder if I can do the same for powerpoint. Thank you once again for your time.

    Steve

  6. #6
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    I do not know PP object model, but it will probably just like in Word.
    [vba] Dim appPP As Object
    Dim oPPP As Object
    Dim Shp As Object

    'The declaration is not needed, because they are fixed at the Office
    'Const msoEmbeddedOLEObject As Long = 7

    Set appPP = CreateObject("Powerpoint.Application")

    Set oPPP = appPP.Presentations.Open("<FullFileName>")

    For Each Shp In oPPP.Shapes
    If Shp.Type = msoEmbeddedOLEObject Then
    MsgBox "I'm here "
    End If
    Next Shp

    oPPP.Close False

    appPP.Quit
    Set appPP = Nothing[/vba]

    Artik
    Last edited by Artik; 02-12-2013 at 06:49 AM.

  7. #7
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •