PDA

View Full Version : Check Word, Powerpoint and Excel files for embedded objects



bassnsjp
02-08-2013, 09:05 PM
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.

Artik
02-10-2013, 11:48 PM
For Word document, like this: 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
Artik

bassnsjp
02-11-2013, 08:47 PM
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

Artik
02-12-2013, 03:48 AM
Where can I find the different types of objects to test for?
For example here (http://msdn.microsoft.com/en-us/library/office/aa432678(v=office.12).aspx).
Or in Object Browser [F2] in VBE, search MsoShapeType Enumeration


Artik

bassnsjp
02-12-2013, 04:55 AM
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

Artik
02-12-2013, 06:31 AM
I do not know PP object model, but it will probably just like in Word.
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

Artik

Kenneth Hobs
02-12-2013, 09:24 AM
Cross-posted: http://www.ozgrid.com/forum/showthread.php?t=174979