Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open an existing .ppt powerpoint file from Visual Basic 6

Status
Not open for further replies.

DeonM

Programmer
Sep 6, 2005
9
ZA
I'm creating a program in Visual Basic 6 to export pictures from existing powerpoint file.
How do I open an existing powerpoint file through a common dialog control. Powerpoint application should not open, basically I just want to open a ppt file leave it in
"memory" and then export the pictures? All this in VB6 and not VBA!
I know I can use the GetObject method but I just don't know how to use this. I have done research but nothing helps!
Hope you guys can help me out!
If you don't understand please ask questions!
Thanks
Regards
 
You can store the filename in a variable, something like:
Code:
Dim PPTFile as String
With CommonDialog1
.CancelError = True
.Filter = "PowerPoint Presentations (*.ppt)|*.ppt"
[green]'.FilterIndex = 1[/green]
.InitDir = "C:\"
.DialogTitle = "Please select a Presentation"
.ShowOpen
End With

PPTFile = CommonDialog1.FileName
You then have the path of the selected file in memory.

The helpfiles for the properties of the common dialog control are pretty helpful so you could have a look at those as well.

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Thanks, OK I looked at al the properties from the common dialog control but I cannot find anything else that could be useful for doing anything else! I think this should work fine!
Can I ask another question in this post or should I post a new one!
The question I want to ask is basically what to do after this!
 
When you say
Powerpoint application should not open
I don't see how you can easily achieve this.
Unless I am totally wrong, you need PowerPoint to interpret the file data (in the same way as if you try to load an Excel file into a textbox you end up with rubbish).

You can load Powerpoint in the background by setting a reference to the object library (Program--References) and declaring an object variable to hold the reference
e.g.
Code:
Dim objPPt As Powerpoint.Application
Then when the user has selected the file via CommonDialog you can use something like
Code:
Dim objPPtPresentation As PowerPoint.Presentation
Dim objPPtSlide As PowerPoint.Slide

Set objPPt = New Powerpoint.Application
objPPt.Presentations.Open CommonDialog1.FileName

For Each objPPtSlide In objPPtPresentation
   'code to process each slide
   
Next

objPPt.Quit

Set objPPt = Nothing

Trevor
 
For the second point you can use Automation.

The following article might do exactly what you are after but might well be a good starting point for working with PowerPoint Automation

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Beaten to it [sad]

I don't see how you can easily achieve this.Unless I am totally wrong
This is an assumption (and I know how dangerous they can be [wink]) but I would have thought you could set the PowerPoint app not to show as you can when you use automation to extract data from Excel?

I may be wrong... [smile]

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
I meant to say that whatever happens, Powerpoint has to "open" but as HarlyQuinn says
you could set the PowerPoint app not to show
This is the default when using
Code:
Set objPPt = New Powerpoint.Application
If you wanted it to be seen you would just add
Code:
objPPt.Visible = True

Trevor
 
Thanks for the help guys, but this code does not help me exactly for what I'm trying to do!
The program I'm creating is a VB6 app. There is a open button to open a ppt file. then I got an Extract button that I press and this will extract all the images from the selected file to a specified folder. So while this is process is happening I don't want powerpoint to open or to show.
This is the code I have to extract the images!
<code>
Sub ExtractImagesFromPres()
On Error GoTo ErrorExtract
Dim oSldSource As PowerPoint.Slide
Dim oShpSource As PowerPoint.Shape
Dim ctr As Integer
Dim sPath As String

sPath = "C:\"

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
</code>

Does this make any sense?
 
I have a powerpoint file that does exactly (except the text saving) what I want to do but only in VB6! How can I send this ppt file to you guys so you can check and see exactly what I'm trying to achieve?
Thanks
 
That's PowerPoint VBA, not VB6 code! VB can't understand the PowerPoint.Slide without a reference in your project to the PowerPoint object.
You will also have to change the reference to ActivePresentation, as that is only applicable to a running PP application

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
DeonM,

To make a code section in a post, change your tags from the <> symbols to square bracktes [].

Ex.

[ignore]
Code:
This is code
[/ignore]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Will do so, thanks!
Here is the code for extracting images from ppt! But I think is in VBA!
Code:
Sub ExtractImagesFromPres()
On Error GoTo ErrorExtract
    Dim oSldSource As PowerPoint.Slide
    Dim oShpSource As PowerPoint.Shape
    Dim ctr As Integer
    Dim sPath As String
    
    sPath = "C:\"

    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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top