Consulting

Results 1 to 15 of 15

Thread: Pop up messages when many programs are executed in VBA PowerPoint

  1. #1

    Pop up messages when many programs are executed in VBA PowerPoint

    Hello All,

    I am working on UI form which has multiple check boxes. My goal is to display a popup message when all check boxed items are executed successfully. As shown below, if "apple" and "spinach" were checked and " okay" button is clicked, a popup message saying

    " Apple and spinach are successful"

    If "spinach" fails to run successfully, then it could popup error message and also successful execution of "apple". Excuse me if this is vague explanation of the problem.

    Please help
    Attached Images Attached Images

  2. #2
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,725
    Location
    What causes the UF to display?

    Is this during a slideshow?

    I assume that Apple, Orange, and Spinach are 3 macros


    Something like this in a standard module

    Option Explicit
    
    
    Sub drv()
        Load UserForm1
        UserForm1.Show
        
    End Sub
    
    
    
    
    Function Apple() As Variant
        If Rnd < 0.5 Then
            Apple = True
        Else
            Apple = False
        End If
    End Function
    
    
    Function Orange() As Variant
        If Rnd < 0.75 Then
            Orange = True
        Else
            Orange = False
        End If
    End Function
    
    
    Function Spinach() As Variant
        If Rnd < 0.95 Then
            Spinach = True
        Else
            Spinach = False
        End If
    End Function

    and this in the UF


    Option Explicit
    
    
    
    
    Private Sub btnOK_Click()
        Dim bApple As Long, bOrange As Long, bSpinach As Long
        Dim sMsg As String
        
        bApple = 1
        bOrange = 1
        bSpinach = 1
        
        With Me
            If .cbApple.Value Then bApple = Apple
            If .cbOrange.Value Then bOrange = Orange
            If .cbSpinach.Value Then bSpinach = Spinach
        End With
        
        If bApple <> 1 Then sMsg = sMsg & IIf(bApple, "Apple ran successfully", "Apple failed") & vbCrLf
        If bOrange <> 1 Then sMsg = sMsg & IIf(bOrange, "Orange ran successfully", "Orange failed") & vbCrLf
        If bSpinach <> 1 Then sMsg = sMsg & IIf(bSpinach, "spinach ran successfully", "Spinach failed") & vbCrLf
        
        Call MsgBox(sMsg, vbOKOnly + vbInformation, "Apple-Orange-Spinach")
    
    
        Me.Hide
        
        Unload Me
    
    
    End Sub
    
    
    Private Sub UserForm_Initialize()
        With Me
            .cbApple.Value = False
            .cbOrange.Value = False
            .cbSpinach.Value = False
        End With
    End Sub
    Attached Files Attached Files
    Last edited by Paul_Hossler; 09-05-2019 at 07:39 AM.
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Hello Paul.

    I created a button on one of slides. So, if I click on this button, it displays UI form. Yes, all check box items are separate macros return in a module. When user clicks on "Okay" button, all macros that were checked run.

    Something like :
    Sub Apple()
    --- other code here--
    MsgBox " Apple is successful "
    End Sub



  4. #4
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,725
    Location
    I edited my original reply to add some concept macros and an attachment

    Give them a test and see if you can use the ideas
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Thank you for the insights, I am working on it and will soon let you know once I achieve it. Is it possible to display error message instead " failed"? Just to let the user be aware of the reason behind failure.

  6. #6
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,725
    Location
    Here's one way



    Option Explicit
    
    
    Sub drv()
        Load UserForm1
        UserForm1.Show
        
    End Sub
    
    
    
    
    Function Apple() As String
        If Rnd <= 0.5 Then
            Apple = "Success: Apple <= 0.5"
        Else
            Apple = "Fail: Apple > 0.5"
        End If
    End Function
    
    
    Function Orange() As String
        If Rnd <= 0.75 Then
            Orange = "Success: Orange <= 0.75"
        Else
            Orange = "Fail: Orange > 0.75"
        End If
    End Function
    
    
    Function Spinach() As String
        If Rnd <= 0.95 Then
            Spinach = "Success: Spinach <= 0.95"
        Else
            Spinach = "Fail: Spinach > 0.95"
        End If
    End Function

    Option Explicit
    
    
    
    
    Private Sub btnOK_Click()
        Dim sApple As String, sOrange As String, sSpinach As String
        Dim sMsg As String
        
        sApple = vbNullString
        sOrange = vbNullString
        sSpinach = vbNullString
        
        With Me
            If .cbApple.Value Then sApple = Apple
            If .cbOrange.Value Then sOrange = Orange
            If .cbSpinach.Value Then sSpinach = Spinach
        End With
        
        If Len(sApple) > 1 Then sMsg = sMsg & sApple & vbCrLf
        If Len(sOrange) > 1 Then sMsg = sMsg & sOrange & vbCrLf
        If Len(sSpinach) > 1 Then sMsg = sMsg & Spinach & vbCrLf
        
        Call MsgBox(sMsg, vbOKOnly + vbInformation, "Apple-Orange-Spinach")
    
    
        Me.Hide
        
        Unload Me
    
    
    End Sub
    
    
    Private Sub UserForm_Initialize()
        With Me
            .cbApple.Value = False
            .cbOrange.Value = False
            .cbSpinach.Value = False
        End With
    End Sub
    Attached Files Attached Files
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    is it possible to do something like:

    Function Apple() As Variant
    --code--
    If code runs well then it is successful. if error comes it is " failed".

    If code = successful Then
    Apple = True
    Else
    Apple = False ' when error occurred anywhere in the code
    End If

    End Function

    what if the code doesn't have IF condition to compare anything with. Here the comparison is whole code executed. Not sure if this practical. Any insights which can guide me.

  8. #8
    Something like code below which doesn't have any conditional statements to compare with.



    Sub changecol(oshp As Shape)

    oshp.Fill.ForeColor.RGB = RGB(255, 0, 0)

    End Sub

  9. #9
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,725
    Location
    ?

    That's usually the macro that gets run when a shape is clicked


    Is that (for example), 'Apple' ?
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  10. #10
    I mean, if 'changecol' run smoothly without any interruption (I took just an example to show the code which don't have If condition in it).

    If I don't have functionality like this wihtin the code :

    If Rnd < 0.75 Then ' something to compare and decide value of orange as true.
    Orange = True
    Else
    Orange = False
    End If




  11. #11
    Hello Paul,

    I achieved it! Thank you so much for your patience. I played with the code snippet you provided at beginning. It took little time to understand

  12. #12
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,725
    Location
    It's a little hard to test with no If's, but do you mean something like this?

    It's preset to False, and if there is an issue, it just exits

    Only if it goes all the way does it return True


    Option Explicit
    
    
    Sub drv()
        Load UserForm1
        UserForm1.Show
        
    End Sub
    
    
    
    
    Function Apple() As Variant
        Apple = False
        
        If Rnd < 0.25 Then Exit Function
        
        Apple = True
        
    End Function
    
    
    Function Orange() As Variant
        Orange = False
        
        If Rnd < 0.5 Then Exit Function
        
        Orange = True
        
    End Function
    
    
    Function Spinach() As Variant
        Spinach = False
        
        If Rnd < 0.95 Then Exit Function
        
        Spinach = True
        
    End Function

    Another way


    Option Explicit
    
    
    Sub drv()
        Load UserForm1
        UserForm1.Show
        
    End Sub
    
    
    
    
    Function Apple() As Variant
       
        Apple = True
        
        On Error GoTo ReturnFalse
        
        If Rnd < 0.25 Then Err.Raise 500, "Apple", "Rotten Apple"
        
        Exit Function
        
    ReturnFalse:
        Apple = False
        
    End Function
    Function Orange() As Variant
       
        Orange = True
        
        On Error GoTo ReturnFalse
        
        If Rnd < 0.5 Then Err.Raise 501, "Orange", "Rotten Orange"
        
        Exit Function
        
    ReturnFalse:
        Orange = False
        
    End Function
    Function Spinach() As Variant
       
        Spinach = True
        
        On Error GoTo ReturnFalse
        
        If Rnd < 0.75 Then Err.Raise 502, "Spinach", "Rotten Spinach"
        
        Exit Function
        
    ReturnFalse:
        Spinach = False
        
    End Function
    Attached Files Attached Files
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  13. #13
    I tried something like this: It worked so far, I should test with multiple test cases.

    Function changecol(oshp As Shape)


    oshp.Fill.ForeColor.RGB = RGB(255, 0, 0)
    changecol = True
    Exit Function

    Err_Handler:
    changecol = False

    End Function

  14. #14
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,725
    Location
    Where does the UF come into play?
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  15. #15
    I modified code in UI as well. But, the above is main functionality I am looking for. Added extra UI button "changecol" under check boxes and just modified your code.

Posting Permissions

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