Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

VB6 And Powerpoint

Hey Guys!
OK, what I'm trying to do is create an app in vb6 where I open a few ppt files and then I want to extract the images from the ppt files to a directory on my hard disk!
The problem is, How do I use this code in my vb6 app. I get error and I think its because the source code is the code used for macros in powerpoint!

Sub ExtractImagesFromPres()
On Error GoTo ErrorExtract
Dim oSldSource As Slide
Dim oShpSource As Shape
Dim Ctr As Integer
Dim sPath As String

sPath = "C:\Test\"
Ctr = 0
For Each oSldSource In ActivePresentation.Slides
For Each oShpSource In oSldSource.Shapes
If oShpSource.Type = msoPicture Then
' Hidden Export method
Call oShpSource.Export(sPath & "Img" & _
Format(Ctr, "0000") & ".JPG", ppShapeFormatJPG)
Ctr = Ctr + 1
End If
Next oShpSource
Next oSldSource
If Ctr = 0 Then
MsgBox "There were no images found in this presentation", _
vbInformation, "Image extraction failed."
End If
Exit Sub
ErrorExtract:
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "Error #" & Err.Number
End If
End Sub

OH and why do I get an error when I insert this code
Dim ppApp As PowerPoint.Application
I get an User defined type not defined error!!!!
I use Win XP and Office 2003!
Thanks for your help and please ask wuestions if you don't understand!

Regards
[1657 byte] By [GermanD] at [2007-11-11 6:42:31]
# 1 Re: VB6 And Powerpoint
Hi,

Go to Projects --> References and in the dialogue box, find Microsoft PowerPoint ... and tick its box.

I haven't got Office 2003 so I can't be more specific about the reference text, I'm still using Office 97 and this gives me a "Microsoft PowerPoint 8.0 Object Library" reference.

Unfortunately my object library doesn't support the Shape.Type property as inIf oShpSource.Type = msoPicture Thenso I can't test your code but I'm sure the correct library will support it.

Trevor
TrevorG at 2007-11-11 17:27:57 >
# 2 Re: VB6 And Powerpoint
My powerpoint reference is clicked but I get the same problem or error regarding Shape.Type property.
Any help, please!!!!
GermanD at 2007-11-11 17:29:07 >
# 3 Re: VB6 And Powerpoint
The error occurs because VB has its own "Shape" object (that doesn't have a "Type" property).
At the head of your subroutine, edit the variable declarations toDim oSldSource As PowerPoint.Slide
Dim oShpSource As PowerPoint.Shape
I've found that this then leads on to another problem wherebyCall oShpSource.Exportgenerates an error (Method or Data member not found) i.e. PowerPoint.Shape objects do no have an Export method or property.

Was the original code written using Powerpoint VBA beause if so it should work correctly in VB so long as the required object library references are used.

Trevor

P.S. You may have more success if you post your problem on a forum that has a dedicated VBA section such as Developer Fusion (http://www.developerfusion.co.uk/forums/forum-6226) or Tek-Tips (http://www.tek-tips.com/threadminder.cfm?pid=707)
TrevorG at 2007-11-11 17:30:06 >