Consulting

Results 1 to 10 of 10

Thread: Display image help

  1. #1

    Display image help

    Hello, I am sure there is a very simple solution, I just can't get it to work.

    When I mouseover a textbox, I would like to display an image in a specific location. I tried creating an image control (called "Image1"), then I created a macro:

    Sub image()
    Set Image1.Picture = LoadPicture("C:\CIMG2817.JPG")
    End Sub
    Afterwards, I created an Action for the textbox- in the mouseover tab, I selected the "image" macro.

    But when I go into slideshow mode... nothing!

    Could anyone offer any advice?

    Thank you.

    (I use powerpoint 2007)
    Last edited by Aussiebear; 04-28-2023 at 08:22 PM. Reason: Added code tags

  2. #2

    More help...

    Sorry for being such a novice, but these should be relatively simple functions if someone could help. If its ok, I would like to expand on this request, as it may be more complicated.

    Basically, what I would like to do, is when I mouseover a textbox, I would like an image to appear, and when the mouse leaves, the image should disappear.

    But in addition to that, each textbox has a different image associated with it. So depending on which textbox is rolled over, a different image should appear. This is something that I have done (in other programming languages) by just assigning a user-defined string for each object, which could then be called upon mouseover.

    Finally, I need to move the image so it is directly above the textbox. I can do this using an activex text control, because it has obvious defined properties such as positions, captions, etc., but it lacks a nice user interface that the regular ppt 2007 textboxes offer.

    I noticed something on oshp, which may have what I am looking for, but I can't find any good literature on how to utilize it. This should all be possible with a few simple lines of code, but I can't figure it out!

    Thank you for your help!

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Hi

    First oshp is just a variable name. By convention many programmers start object variables with "O" and indicate the type so oshp or osh simply refers to an object that is a shape while osld would be an object that is a slide.

    Try inserting a "normal" shape to hold the picture eg a rectangle and name it eg Pic1 so that it can be identified easily. In 2007 you can do this in the selection pane (in earlier versions you will need code)

    Now assuming Pic1 is on slide 1 (make the obvious change if not)

    Sub pic1()
    ActivePresentation.Slides(1).Shapes("Pic1").Fill.UserPicture "C:\Documents and Settings\John\Desktop\john.jpg"
    End Sub
    will fill it with the picture (obviously change the address)

    and this will kill the picture

    Sub pic1Kill()
    ActivePresentation.Slides(1).Shapes("Pic1").Fill.Visible = False
    End Sub
    You will then need to arrange two mousover shapes one to trigger the fill and another around the first to trigger the kill.

    Hope that makes sense

    Another option would be to fill the shapes manually with the picture and simply make the .visible object true or false. Note that there is a bug which sometimes affects animation if you do this.

    eg
    Sub pic1Kill()
    ActivePresentation.Slides(1).Shapes("Pic1").Visible = False
    End Sub
    hope that helps
    Last edited by Aussiebear; 04-28-2023 at 08:23 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    Thanks for the information.

    I am going to have a multiple different shapes that will have mouseovers. I was hoping, to make coding simpler, I could just have one sub, and use information stored in the particular shape (like the position, shape name, etc.). Is there a way to determine exactly which shape activated the macro?

    Thanks!

    ~MK

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Maybe something like this:

    Sub pics(oshp As Shape)
    Select Case oshp.Name
        Case Is = "Oval 3"
            'do something
        Case Is = "Oval 4"
            'do something else
    End Select
    End Sub
    You can have as many Case Is statements as you need. All the shapes would have the same mouseover action (Run Macro pics)

    Hope that helps
    Last edited by Aussiebear; 04-28-2023 at 08:24 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    So far, I'm in pretty good shape! Almost to the point where I can just point to 1 macro for every single shape. I can now do so with all the shapes in 1 slide, but now I must extend this to multiple slides.

    Here is what I have so far:
    Sub image(oshp As Shape)
    current_dir = CurDir()
    image_name = oshp.Name
    Slide1.Image1.Picture = LoadPicture(current_dir & "\Pictures\" & image_name & ".bmp")
    Slide1.Image1.Visible = False
    Slide1.Image1.Left = oshp.Left + (oshp.Width - Slide1.Image1.Width) / 2
    If (oshp.Top - Slide1.Image1.Height) > 0 Then
        Slide1.Image1.Top = oshp.Top - Slide1.Image1.Height
    ElseIf (oshp.Top - Slide1.Image1.Height) < 0 Then
        Slide1.Image1.Top = oshp.Top + oshp.Height
    End If
    Slide1.Image1.Visible = True
    End Sub

    So now I can't figure out how to turn Slide1.Image1 into something that actually grabs the current slide, as opposed to just Slide1... Any ideas? Image1 is an image control, not a shape.
    Last edited by Aussiebear; 04-28-2023 at 08:25 PM. Reason: Adjusted the code tags

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    You need to grab a reference to the current position (i) using the method
    ActivePresentation.SlideShowWindow.View.CurrentShowPosition
    and then use this to reference the shape using

    ActivePresentation.Slides(i).Shapes("Image1").OLEFormat.Object
    Last edited by Aussiebear; 04-28-2023 at 08:26 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8

    Slide Transition

    Great, thanks for your help! The Image display is working very well now- one macro to control every single textbox.

    Now onto the next challenge. I am creating a UI in which images of left, right, up and down arrows control which slide to go to next. When I click on the left button, the slide should transition to the left. And when I click on the right button, the slide should transition to the right. Unfortunately, right now, the transition is defined by the slide I am moving to, and not by which slide I came from.

    So basically, I need a simple macro that I will install as a mouseover that finds out which slide the arrow will transition to. But I can't figure out how to access this.

    Here's what I have so far: (I need to find out which slide is present in the ActionSettings and put it into intendedSlide)

    Sub arrow(oshp As Shape)
    intendedSlide = oshp.ActionSettings.Item.Hyperlink.Parent
    Select Case oshp.Name
        Case Is = "left"
            ActivePresentation.Slides(intendedSlide).SlideShowTransition.EntryEffect = ppEffectPushRight
        Case Is = "right"
            ActivePresentation.Slides(intendedSlide).SlideShowTransition.EntryEffect = ppEffectPushLeft
        Case Is = "up"
            ActivePresentation.Slides(intendedSlide).SlideShowTransition.EntryEffect = ppEffectPushDown
        Case Is = "down"
            ActivePresentation.Slides(intendedSlide).SlideShowTransition.EntryEffect = ppEffectPushUp
    End Select
    End Sub
    Any suggestions?
    Last edited by Aussiebear; 04-28-2023 at 08:26 PM. Reason: Adjusted the code tags

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    This is how I would do it

    When you set an internal hyperlink the shape has a sub address in this form

    SlideID,Slide Number, Title

    It might seem obvious to go for the number but don't - this is the original slide number if you move slides it may change always use the ID which will almost always be a three digit number eg 256 If you have lots of slides maybe write a routine to check how many digits before the first ,

    Here's an idea then

    Dim jump As String
    Dim slidenum As Integer
    jump = oshp.ActionSettings(ppMouseClick).Hyperlink.SubAddress
    'check there is a hyperlink
    If jump <> "" Then
        'usually left 3 will be the slide ID sub address in ID,number,Title
        'you may want to make this a more complex check if you have a lot (>700) of slides
        jump = Left$(jump, 3)
        slidenum = ActivePresentation.Slides.FindBySlideID(jump).SlideIndex
        ActivePresentation.Slides(slidenum).SlideShowTransition.EntryEffect = ppEffectBoxIn 'etc
    End If
    Last edited by Aussiebear; 04-28-2023 at 08:28 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  10. #10
    Thank you very much for all your help, John! That SubAddress is what I was missing... And thanks for the tip for the SlideID; it wasn't really clear how the slides() actually accessed slides.

    Anyways, it looks like the code part of this powerpoint is up and running! Amazing what one can do with only 2 macros. Now to begin adding the content...

    Thank you again!

    Quote Originally Posted by John Wilson
    This is how I would do it

    When you set an internal hyperlink the shape has a sub address in this form

    SlideID,Slide Number, Title

    It might seem obvious to go for the number but don't - this is the original slide number if you move slides it may change always use the ID which will almost always be a three digit number eg 256 If you have lots of slides maybe write a routine to check how many digits before the first ,

    Here's an idea then

    Dim jump As String
    Dim slidenum As Integer
    jump = oshp.ActionSettings(ppMouseClick).Hyperlink.SubAddress
    'check there is a hyperlink
    If jump <> "" Then
        'usually left 3 will be the slide ID sub address in ID,number,Title
        'you may want to make this a more complex check if you have a lot (>700) of slides
        jump = Left$(jump, 3)
        slidenum = ActivePresentation.Slides.FindBySlideID(jump).SlideIndex
        ActivePresentation.Slides(slidenum).SlideShowTransition.EntryEffect = ppEffectBoxIn 'etc
    End If
    Last edited by Aussiebear; 04-28-2023 at 08:28 PM. Reason: Adjusted the code tags

Posting Permissions

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