dynamically change powerpoint

spinkung

Registered User.
Local time
Today, 00:30
Joined
Dec 4, 2006
Messages
267
Hi All,

I'm trying to dynamically update some text boxes on a powerpoint presentation from access vba.

I need to be able to loop through the text field/text box objects on a slide so i can set their values.

I have....
Code:
Dim strPowerPointFile As String
Dim pptobj As PowerPoint.Application
Set pptobj = New PowerPoint.Application
pptobj.Visible = True
pptobj.WindowState = ppWindowMinimized
    
strPowerPointFile = CurrentProject.Path & "\My PPT presentation.ppt" 

With pptobj.Presentations.Open(strPowerPointFile)
        Dim ppSlide As PowerPoint.Slide
        For Each ppSlide In .Slides
            Debug.Print ppSlide.SlideNumber     'this works fine
                Dim ppField As PowerPoint.  [COLOR="Red"]'WHAT DO I PUT HERE??[/COLOR]
                For Each ppField In .Slides  [COLOR="Red"]'WHAT DO I PUT HERE??[/COLOR]
                Debug.Print ppField. [COLOR="Red"]'so that i can get the text box name here and set the value of it??[/COLOR]


Many Thanks,
Spin.
 
Excellent, thankyou.

i managed to get it working with

Code:
        For Each ppSlide In .Slides
            If ppSlide.SlideNumber = 1 Then
                For Each ppShape In ppSlide.Shapes
                    If ppShape.ID = 3074 Then
                        ppShape.TextFrame.TextRange.Text = Me.cmb_Courier.Value & " H1 2009 Strategic Review"
                    ElseIf ppShape.ID = 3075 Then
                        ppShape.TextFrame.TextRange.Text = Me.cmb_meetRoom.Value
                    End If
                Next
            End If
        Next

now i just need to be able to save it when it closes, back to the drawing board.

spin :)
 
New requierment.....


hello again,

i thought i should leave this add on in this topic as it's related. I have managed to dynamically update ppt text boxes from access using the .shapes function to loop through all the shapes then set them as above.

i now want to dynamically change an image. i have got this from ms.....

Code:
If ppShape.ID = 3076 Then
Set ppShape = ppSlide.Shapes.AddPicture("\my img.gif, msofalse, msotrue, 1, 1)
ElseIf ppShape.ID = 3074 Then....etc

but i keep getting an error saying specified value out of range.

can anyone help ....PLEEEEEEEASE.

thanks,spin.
 
I've shown you mine, now show me yours.

Please post your sample database, show us what you have.
 
Hi,

thanks for your reply.

i've attched a copy of what i've got so far. I need to change an image in slide 1 dependant on what courier is selected in my drop down box on my access form.

I've commented the code where it should happen, it'll debug there anyway.

any help would be great, thanks. spin.
 

Attachments

hi gemma,

i can't find the unmatched quote in my code. when i assign the image path to a variable it looks like this to me....

d:\Documents and Settings\GFrewin\Desktop\My Power Point test\Pics\City Link.gif

...then i use it later as...

Code:
Set ppShape = ppSlide.Shapes.AddPicture(courLogo, msofalse, msotrue, 1, 1)

spin.
 
you quoted this code

If ppShape.ID = 3076 Then
Set ppShape = ppSlide.Shapes.AddPicture("\my img.gif, msofalse, msotrue, 1, 1)
ElseIf ppShape.ID = 3074 Then....etc

the red bit could certainly produce some strange errors if accepted by the compiler
 
hi,

i made a mistake in the quoted part on this post but in the actual attachment the image path is assigned to a variable which is fine (i think).

spin.
 
OK, so it look as though ppt is a pain in the ass with no paste special feature (ppt 2007).

so the solution was to (from access vba)...

1. create an excel instance and loop though my chart objects in excel.
2. copy those charts into an instance of word using paste special.
3. copy the picture from word into my instance of ppt.

...all very confusing and fiddly but it works now with this function...

Code:
Sub ExcelChartToPowerpointImage(xlChartObj As Excel.ChartObject, ppSlide As PowerPoint.Slide, _
                                sngTop As Single, sngLeft As Single)
                                
    Dim wdDoc As Word.Document
    Dim wdApp As New Word.Application
    Dim sh As PowerPoint.Shape
    
    xlChartObj.Copy
    Set wdDoc = wdApp.Documents.Add()
    wdDoc.Select
    wdApp.Selection.PasteSpecial DataType:=3
    wdDoc.Shapes(1).Select
    wdApp.Selection.Copy
    Set sh = ppSlide.Shapes.Paste(1)
    sh.Top = sngTop
    sh.Left = sngLeft
    wdDoc.Close (wdDoNotSaveChanges)
    wdApp.Quit
End Sub

...called using this line of code...
Code:
For Each sht In xlwb.worksheets
     For Each cht In sht.chartobjects
         ExcelChartToPowerpointImage cht, ppSlide, cht.Index * 160, 95
     Next
Next


I still can't get an .jpg image from file to paste into a ppt picture shape though so anyone with that knowledge i'd love to hear from. this doesn't work but is on the right track i think...

Code:
myLogo = "\mypath\myimg.jpg"
Set ppShape = ppSlide.Shapes.AddPicture(myLogo , msofalse, msotrue, 1, 1)

thanks, spin
 

Users who are viewing this thread

Back
Top Bottom