Don't run script when active page is clicked

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
If the active page is page3 or page5, then don't say hello when it's clicked.

It's giving me a headache. Can someone fix that for me?

Code:
Private Sub MultiPage1_Click (ByVal Index As Long )
With MultiPage1
Select Case .Value 
    Case 2, 4 : MsgBox "Hello"
End Select 
End With
End Sub
 
I know of no way to stop Hello from popping up second time you select Multipage page.

But if it would work you could have the script say Hello and then hide the Multipage Page

Trying this:
Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
'Modified  1/20/2019  11:01:48 PM  EST
With MultiPage1
    Select Case .Value
        Case 0, 1, 3: MsgBox "Hello"
        .Pages(MultiPage1.Value).Visible = False
    End Select
End With
End Sub
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Perhaps
Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
    Static Flag As Boolean
    Select Case MultiPage1.Value
        Case 2, 4
            If Not Flag Then MsgBox "hi"
            Flag = True
        Case Else
            MsgBox "hi"
    End Select
End Sub
 
Last edited:
Upvote 0
Cool, cool!!!


I made these adjustments and it's working as expected slightly :

Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
    Static Flag As Boolean
    Select Case MultiPage1.Value
        Case 2, 4
            If Not Flag Then MsgBox "hi"
            Flag = True
        Case Else
        [B]    Flag = False[/B] 
    End Select
End Sub
The only issue with that is that when I make the page3 (value 2) active, then immediately click the page5 (value 4), it doesn't say hi.

But it does when I click any of the remaining pages before clicking.

I hope someone can nail that part of it for me.

Regards
 
Last edited:
Upvote 0
I know of no way to stop Hello from popping up second time you select Multipage page.

But if it would work you could have the script say Hello and then hide the Multipage Page

Trying this:
Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
'Modified  1/20/2019  11:01:48 PM  EST
With MultiPage1
    Select Case .Value
        Case 0, 1, 3: MsgBox "Hello"
        .Pages(MultiPage1.Value).Visible = False
    End Select
End With
End Sub


I have used something like this before. I just feel there should be a cooler way. I am enjoying your concern. Thanks a lot.
 
Upvote 0
Yes I knew you may not like this plan but the only one I could come up with. I tried Mikes code and it did not work the way you asked for. I noticed some problems but do not know how to fix it. Maybe he will be back.
I have used something like this before. I just feel there should be a cooler way. I am enjoying your concern. Thanks a lot.
 
Upvote 0
Cool, cool!!!

The only issue with that is that when I make the page3 (value 2) active, then immediately click the page5 (value 4), it doesn't say hi.
...
I wasn't quite sure what your requirments were.
Perhaps this
Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
    Static LastPage As Long
    Select Case (LastPage & ":" & MultiPage1.Value)
        Case "2:2", "4:4"
            Rem do nothing
        Case Else
            MsgBox "hi"
    End Select
    LastPage = MultiPage1.Value
End Sub
 
Last edited:
Upvote 0
I wasn't quite sure what your requirments were.
Perhaps this
Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
    Static LastPage As Long
    Select Case (LastPage & ":" & MultiPage1.Value)
        Case "2:2", "4:4"
            Rem do nothing
        Case Else
            MsgBox "hi"
    End Select
    LastPage = MultiPage1.Value
End Sub

Okay this one is cooler.

However, it shouldn't say the Hi for those remaining pages at all.

Let me be very clear here:
1. When I click page3 (index 2) or page5 (index 4), then say hi
2. When page3 is already active and I click it again, don't say hi
3. When page5 is already active and I click it again, don't say hi


So currently the code you wrote is toggling between the hi and no hi correctly for pages 3 and 5. However, it says hi for the other pages , which I don't want them say hi.

Regards
 
Upvote 0
How about this?

Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
    
    Static init As Boolean
    Static previousIndex As Long
    
    If Not init Then
        init = True
        previousIndex = -1
    End If
    
    With MultiPage1
        Select Case Index
            Case 2, 4 'Tab3 or Tab5
                If Index <> previousIndex Then
                    MsgBox .Pages(Index).Caption & " Hello", Title:="Index = " & Index
                End If
            Case Else
                MsgBox .Pages(Index).Caption & " Hello", Title:="Index = " & Index
        End Select
        previousIndex = Index
    End With
    
End Sub
 
Upvote 0
How about this?

Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
    
    Static init As Boolean
    Static previousIndex As Long
    
    If Not init Then
        init = True
        previousIndex = -1
    End If
    
    With MultiPage1
        Select Case Index
            Case 2, 4 'Tab3 or Tab5
                If Index <> previousIndex Then
                    MsgBox .Pages(Index).Caption & " Hello", Title:="Index = " & Index
                End If
            Case Else
                MsgBox .Pages(Index).Caption & " Hello", Title:="Index = " & Index
        End Select
        previousIndex = Index
    End With
    
End Sub

Sure!!!

After turning off the case else alert, everything is working smoothly .

I really appreciate your help .

I mean all those who gave a helping hand :)
 
Upvote 0
Code:
Private Sub MultiPage1_Click(ByVal Index As Long)
    Static LastPage As Long
    If MultiPage1.Value = 2 Then
        If LastPage <> 2 Then MsgBox "hi"
    ElseIf MultiPage1.Value = 4 then
        If LastPage <> 4 Then MsgBox "hi"
    End If
    LastPage = MultiPage1.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top