Consulting

Results 1 to 10 of 10

Thread: General question from a beginner

  1. #1

    General question from a beginner

    I am pretty good with Access VBA but a beginner with Powerpoint VBA. I have searched the internet far and wide using every key word I can think of, but I have not found much help - basically an introduction and thats about it. I have figured out how to connect to an external data source, but now I need to learn how to use that data on slides. Triggering events in Access is pretty simple, but I have NO clue how it works in Powerpoint. Usually, if I see a good example, I can take it from there with minimal help. So, with that said, can anyone point me in the right direction? I guess the first thing would be to ask some simple questions.

    1. Can data be take from an external source and assigned to a text box on a slide?
    2. Can an event be triggered each time the presentration loops.

    I'm sure I will have more questions but lets start with these. Basically, what I'm trying to do is create a presentation that will loop continuously and check for new data each time it loops. I would appreciate any help anyone could give me on this.

    Thanks,

    Mike

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Events in PPT are not well supported.

    There are two ways to get what you need

    Create a with events Class Module


    You can then access the event for slideshowNextSlide and use this to check that you are on slide 1 in the show.

    You will need to auto create an new instance of the class though which is difficult without an AddIn. And of course you will need to know how to create the Class.

    METHOD 2

    Use a sub routine like this:

    Sub OnSlideShowPageChange(SW As SlideShowWindow)
    If SW.View.CurrentShowPosition = 1 Then
    'run your code
    End If
    End Sub
    This also has problems and will not run reliably until the vb editor is accessed by the file! However you can acheive this by placing any item (eg command button) from the control toolbox just off slide in slide 1. It doesn't need any code adding just having the button there will do it.

    Hope that makes sense.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Perhaps I should explain what I'm trying to accomplish. I have a slide show with approx 8 slides that loops continuously on a large monitor in our facility. 2 of these slides show safety data (days since last recordable, TCIR, daily safety message, etc. What I'm actually attempting to do, is have the PP Presentation check for new data each time it loops. For instance, after midnight, it would compare the date of the last recordable to the current date and update this textbox accordingly.

    I have actually done this using Access vba which builds the slide show at runtime. The problem with this is that it will only check for new data if I stop and rebuild the slide show each time. It works OK but it is not a smooth transition from the last slide to the first.

    Any additional help or insight would be appreciated.

    Thanks,

    Mike

  4. #4
    John (or any one else that wants to comment),

    I tried your suggestion but with no success. I have a question concerning slide numbers. In a slide show that contains 8 slides, the first slide (at the top of the left panel) is referred to as "Slide8" and the second as "Slide7" and so on. In other words, the slide show is constructed in reverse order building the last slide first and the next to last slide second, etc. However, if I use the following code to delete all objects on a slide:

    With Application.ActivePresentation.Slides(1).Shapes
            For intShape8 = .Count To 1 Step -1
                .Item(intShape8).Delete
            Next
        End With
    this refers to the slides in top to bottom order. In other words, Slide(1) refers to the first or top slide in the left panel, Slide(2) refers to the second slide and so on. So with that said, where exactly do I place this control (button) and exactly which slide do I reference in the code?

    Thanks again,

    Mike
    Last edited by SamT; 11-24-2013 at 08:29 AM. Reason: Added Code Tags Using the # Button

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    ActivePresentation.Slides(1) is always the first slide.

    I guess when you say left panel you mean in the VB Editor under Microsoft PowerPoint Objects??

    Slide1 here is totally different from Slides(1) (Good call Microsoft BTW!!)

    Slidex here is the NAME of the Slide Code Container and only shows if you have activX objects on the slide. Slide1 does NOT (necessarily) refer to the first slide - it's the first slide you added the object to. If this was the fourth slide it would still name it Slide1. Yep it is crazy!

    The command button I suggested should have NO code at all. When there is a Command Button on slide one (even with no code) it accesses the vbe for a moment. There is a bug in OnSlideShowPageChange which makes it unreliable UNLESS the VBE has been accessed that session. That is the purpose of the button nothing else.

    So if you want your update code to run when slide one opens:
    Sub OnSlideShowPageChange(SW As SlideShowWindow)
        If SW.View.CurrentShowPosition = 1 Then
            'insert your code instead of this
            MsgBox "This is slide one"
        End If
    End Sub
    I put a very simple example here
    Last edited by John Wilson; 11-21-2013 at 08:40 AM. Reason: format code
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    John,

    Actually what I mean by "left panel" is the panel in the slide show window that shows icons of all the slides in the presentation in order from 1 to x. When I build the slide using VB code, I have to reference the last slide (in this case slide 8) as slide1 and the first slide as slide8. Conversely, when I use the VB code to delete all objects on a slide, I have to reference them as they appear in the "tabbed" panel in the slide show view. (hope this makes sense). This is similar to the way it works if you build the slide show in Access VBA. The slides are constructed at runtime in reverse order. In other words, the first slide that is encountered in the VB code will appear last in the slide show.

    Now, I experimented with the code you sent me and finally got it to work. I added a button just off of slide 1. All seems to work well except for just one minor detail. I have a slide that shows the current time. Each time this slide appears, it momentarily shows the time that is saved on the slide view window and then it changes to the current time. If I stop the presentation, the new time will appear in the slide show window. Each time I stop the show, this textbox will show an updated time. However, when I resume the slide show, it will first show that new time momentarily before showing the correct time. Any thoughts on this?

    Thanks,

    Mike

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Slide 8 (ie the eighth slide in the presentation) would never normally be referenced as Slide1 unless you are refering to ActivX objects on the slide. Even then there is no need to refer to the slide in this way.

    The slide show window doesn't normally have a left panel so I'm still confused. Can you post a screenshot.

    Which slide has the current time?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    PP_ScreenShot.jpg

    See image above. The panel I'm referring to is on the left, showing each slide in the presenation numbered from 1 thru x (in this case 1 thru 8). In the code below, the first section deletes all objects on slide 7 (refer to the left panel in the image). Here I have to actually refer to it as slide 7 (which makes sense). However, in the code following this, I replace all the objects I deleted. (there may be an easier way to do this, but I'll get to that later). In this section you will see that I have to refer to it as "Slide2" (this makes NO sense).

    'Begin Slide 2**************************************
        'Delete all objects on slide 2 (slide7)
        With Application.ActivePresentation.Slides(7).Shapes
            For intShape2 = .Count To 1 Step -1
                .Item(intShape2).Delete
            Next
        End With
        
        'Textbox Caption - Current Time
        Slide2.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=30, Top:=50, _
            Width:=660, Height:=100).TextFrame.TextRange.Text = "Current Time"
        With Slide2.Shapes(1).TextFrame.TextRange.Characters
            .Font.Name = "Ariel"
            .Font.Size = 96
            .Font.Bold = True
            .Font.Italic = True
            .Font.Color.RGB = RGB(122, 131, 160)
        End With
        Slide2.Shapes(1).TextEffect.Alignment = msoTextEffectAlignmentCentered

    There are 4 other objects that are deleted and re-added but you get the idea.

    Now as for the better option, the only way I could figure to change the text or value of an object was to delete it and recreate it each time. The reason I deleted all objects on the slide is because they are numbered sequencially in the order they are read. If I deleted an object from the middle (say Slide2.Shape(3)) the objects would get re-numbered and create all kinds of havoc.

    Now with that said, is there a way I can assign a new value to an object without deleting and recreating it?

    I hope this makes sense because it is very confusing to me.

    Thanks for your help.

    Mike
    Last edited by SamT; 11-24-2013 at 08:47 AM. Reason: Added Code Tags Using the # Button

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    That makes no sense at all. You do not need to delete objects to change the text. Code like this should just error With Slide2.Shapes(1).TextFrame.TextRange.Characters unless you have declared an object var slide2 or there are activX objects

    Can you send me a couple of slides Slide 7 in particular.
    john ATSIGN pptalchemy.co.uk
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  10. #10
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    John,

    Thank you for the information. I have done as you suggested. It seemed best to me as well.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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