Results 1 to 16 of 16

Thread: PPT 2010 - Open UserForm based on Slide#

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    PPT 2010 - Open UserForm based on Slide#

    Hello,

    I was wondering if it is possible to use a vba code that will open a UserForm based on the current open slide in Normal/Edit View?

    I tried the code below, but I'm getting an error message (Object variable or With block variable not set.
    Code:
    Sub UserForm()
    Dim ActiveSlide As Slide
    
    If ActiveSlide = ActivePresentation.Slides(1) Then
        frmChecklist.Show vbModeless
    End If
    
    End Sub
    What I need to do is:
    •If Slide 0 is the current active presentation slide, then open userform1.
    •If Slide 1 is the current active presentation slide, then open userform1 and userform2.
    •etc.

    Thank you

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PPT 2010 - Open UserForm based on Slide#

    Dim ActiveSlide As Slide
    you have dimensioned activeslide in the procedure, which creates a variable that will over ride the application's activeslide, try removing that line
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PPT 2010 - Open UserForm based on Slide#

    Hello,

    I have tried removing that line and I am getting the following error message "Run-time error '438': Object doesn't support this property or method".

    The below line is highlighted with that error.
    Code:
    If ActiveSlide = ActivePresentation.Slides(1) Then

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PPT 2010 - Open UserForm based on Slide#

    Hello,

    I'm still looking for some assistance for my issue.

    I have the below code, but the User Form does not popup when I go to a new slide in the Normal/Edit view/mode.
    Code:
    Dim sld As Slide
    
    Set sld = ActiveWindow.View.Slide
    
    Select Case sld.Name
        Case ActivePresentation.Slides(1).Name
            UserForm1.Show vbModeless
        Case ActivePresentation.Slides(2).Name
            MsgBox "Slide 2"
    End Select
    Any help would be appreciated.

    Thank you

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PPT 2010 - Open UserForm based on Slide#

    I have the below code, but the User Form does not popup
    do you have this code in some event for when the slide is shown? possibly slideselectionchanged, slideshowonnext or most likely should be slideshownextslide

    if the code is in some other procedure it would need to be run by the user, click a button or some such
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PPT 2010 - Open UserForm based on Slide#

    Hello,

    I originally had it as Sub UserForm()

    I changed it to the below and nothing happens at all. I can't even find it under macros.
    Code:
    Sub SlideSelectionChanged(ByVal SldRng As SlideRange)
    Dim sld As Slide
    
    Set sld = ActiveWindow.View.Slide
    
    Select Case sld.Name
        Case ActivePresentation.Slides(1).Name
            frmChecklist.Show vbModeless
        Case ActivePresentation.Slides(2).Name
            frmChecklist.Show vbModeless
            MsgBox "Slide 1"
    End Select
    
    End Sub

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PPT 2010 - Open UserForm based on Slide#

    you should be able to select the slide change events from the drop down lists at the top of the code module, so you should always be able to find it from those lists
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PPT 2010 - Open UserForm based on Slide#

    Hello,

    I just updated the code to:

    Code:
    Sub SlideSelectionChanged()
    Dim sld As Slide
    
    Set sld = ActiveWindow.View.Slide
    
    Select Case sld.Name
        Case ActivePresentation.Slides(1).Name
            frmChecklist.Show vbModeless
        Case ActivePresentation.Slides(2).Name
            frmChecklist.Show vbModeless
            MsgBox "Slide 1"
    End Select
    
    End Sub
    It does not open the userform when the file is opened and it does not change userform when I go to slide2. I want this macro to work in the Edit mode of the PowerPoint presentation. The only way it works is if I execute the macro manually, but I need it to do it automatically once I go to the next slide.

    Suggestions above is not helping my situation.

    Thank you

  9. #9
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: PPT 2010 - Open UserForm based on Slide#


  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PPT 2010 - Open UserForm based on Slide#

    the procedure in post #6 look more correct for event driven than post #8

    BUT as far as i can tell, it is not a default event, so you need to have an application object withevents

    see https://msdn.microsoft.com/en-us/lib...ffice.11).aspx

    pls note, i do not have power point installed, so i can not check or test any suggestions made, as in post #7 if you can not see that event in the drop down lists you will need an application object with events, you will the find the event in the drop down lists, under the application object, or find some alternative in the default events

    you will need in an object module
    Code:
    Public WithEvents app As Application
    then you will need code to assign the application to the object, which would appear to be more complex then in word or excel as there may not be any equivalent to the default document or workbook open event, where you can set the application object
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PPT 2010 - Open UserForm based on Slide#

    Hello,

    I will try this out.

    In the meantime, is it possible to tie the userform to the slide header instead of the slide#?

    Thank you

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PPT 2010 - Open UserForm based on Slide#

    is it possible to tie the userform to the slide header
    i am sure it would be equally as easy as using the slide number, it would still require events to be enabled for the code to run when the slide is changed
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PPT 2010 - Open UserForm based on Slide#

    Quote Originally Posted by westconn1 View Post
    i am sure it would be equally as easy as using the slide number, it would still require events to be enabled for the code to run when the slide is changed
    Would you happen to know what the code would look like to get the slide header name?

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PPT 2010 - Open UserForm based on Slide#

    Code:
    Sub GetTextsOfTitleSlides()
    	  Dim sld As Slide
    	  For Each sld In ActivePresentation.Slides
    	  With sld
    	    If .Layout = ppLayoutTitle Then
    	      Debug.Print _
    	        .SlideIndex & vbTab & _
    	        .Shapes.Title.TextFrame.TextRange
    	    End If
    	  End With
    	  Next sld
    	End Sub
    try like the above, i copied from http://vba.relief.jp/powerpoint-macr...-title-slides/
    i am not sure if header name an title are the same thing, there is a header in each slide, but i do not believe it would have a name, only a content or contain a shape with some text
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PPT 2010 - Open UserForm based on Slide#

    Hello,

    I had to tweak the code a bit to include slide with the layout of Section Header. This allows me to get the slide header name for the slides that are Title Slide and Section Header Layout types. Now there are some slides that looks like are Blank layout with headers.
    How can I get those slide headers to also appear in the code?
    Also, how can I use the code below with the original code to bring up the userform based on the slide header name?

    Code:
    Sub GetSlideTitle()
    
    Dim sld As Slide
    
        For Each sld In ActivePresentation.Slides
          With sld
            If .Layout = ppLayoutTitle Or ppLayoutSectionHeader Then
              Debug.Print _
                .SlideIndex & vbTab & _
                .Shapes.Title.TextFrame.TextRange
            End If
          End With
        Next sld
    
    End Sub
    Original code for userform using slide header name:
    Code:
    Private Sub SlideSelectionChanged()
    Dim sld As Slide
    
    Set sld = ActiveWindow.View.Slide
    
    Select Case sld.Name
        Case ActivePresentation.Slides(1).Name
            Slide0.Show vbModeless
        Case ActivePresentation.Slides(2).Name
            Slide0.hide
            Slide1.Show vbModeless
        Case ActivePresentation.Slides(3).Name
            Slide1.hide
            Slide2.Show vbModeless
    End Select
      
    End Sub
    Thank you

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PPT 2010 - Open UserForm based on Slide#

    i would think something like
    Code:
            If .Layout = ppLayoutTitle Or ppLayoutSectionHeader Then
              select case _
                .SlideIndex & vbTab & _
                .Shapes.Title.TextFrame.TextRange
                   case "some title"
                         userformx.show
                   case "my tilte"
                         userformy.show
              end select
            End If
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width