none
Creating a toggle button RRS feed

  • Question

  • As a sometime creator of very simple macros, I have attached the following macro to a button on the ribbon:

    Sub IBWMShowNotes()
    ' Macro IBWMShowNotes
    ' Macro Recorded Fri 24 Oct '14 by Ken
    ' This macro splits the screen and displays the IBWM Notes form in the lower pane
        FormViewShow
        DetailsPaneToggle
        ViewApplyEx Name:="IBWM Notes", ApplyTo:=1
    End Sub

    I would like to make the button into a toggle button, so that if the screen is already split (i.e. after the macro has been run the first time), clicking the button will remove the split and leave the upper pane as a single pane. Nothing I have tried so far seems to work, which is a fair indication of my limited skills.

    Any assistance would be greatly appreciated.

    Ken

    Monday, November 17, 2014 3:21 AM

Answers

  • Toon,

    Incorporate this into your code:

    Sub PaneCheck()
    If ActiveWindow.BottomPane Is Nothing Then
        [do what you want for single pane]
    Else
        [do what you want for split screen]
    End If
    End Sub

    John

    • Marked as answer by KenHolzman Monday, November 24, 2014 2:31 AM
    Friday, November 21, 2014 3:37 PM
  • Hi Ken,

    Private detailsPaneHidden As Boolean
    
    Sub IBWMShowNotes()
    
        If detailsPaneHidden Then
            DetailsPaneToggle
            detailsPaneHidden = False
        Else
            ViewApplyEx Name:="IBWM Notes", ApplyTo:=1
            detailsPaneHidden = True
        End If
       
    End Sub
    

    The only limitation is that this one will always show the 'IBWM Notes' view in the details pane on the first click (reason: I can't find a way to check if the details pane is visible)

    Hope this helps

    • Marked as answer by KenHolzman Monday, November 24, 2014 3:53 PM
    Friday, November 21, 2014 1:00 PM

All replies

  • Hi Ken,

    I don't think there's an easy way to check if the details pane is visible, but following code should do the trick:

    Dim detailsPaneVisible As Boolean
    
    Sub IBWMShowNotes()
    
        If detailsPaneVisible Or IsNull(detailsPaneVisible) = True Then
            ViewApplyEx Name:="IBWM Notes", ApplyTo:=1
            detailsPaneVisible = True
        Else
            DetailsPaneToggle
            detailsPaneVisible = False
        End If
       
    End Sub
    

    Hope this helps

    Monday, November 17, 2014 3:12 PM
  • Hi Toon,

    Thanks for your response. I have tried the coding and it works well for toggling between the split screen and single pane modes, but it always ends up with the Task Form in the lower pane instead of the IBWM Notes view. do you have any suggestions as to why this is occurring and how to fix it?

    Regards,

    Ken

    Tuesday, November 18, 2014 5:29 AM
  • Hi Ken,

    Just tested the code again and apparently there was a small mistake in the code, please try this:

    Dim detailsPaneVisible As Boolean
    
    Sub IBWMShowNotes()
    
        If detailsPaneVisible Or IsNull(detailsPaneVisible) = True Then
        
            ViewApplyEx Name:="IBWM Notes", ApplyTo:=1
            detailsPaneVisible = False
        Else
    
            DetailsPaneToggle
            detailsPaneVisible = True
        End If
       
    End Sub
    

    Hope this helps

    Tuesday, November 18, 2014 1:39 PM
  • Hi Toon,

    Soooooo close.

    The new code works perfectly except for the first time it is run when it again shows the Task Form in the lower pane. When I run it a second time it switches to the IBWM Notes view and then toggles perfectly.

    Hope you can give it a final tweak so the first time works as well.

    Regards,

    Ken

    Friday, November 21, 2014 8:52 AM
  • Hi Ken,

    Private detailsPaneHidden As Boolean
    
    Sub IBWMShowNotes()
    
        If detailsPaneHidden Then
            DetailsPaneToggle
            detailsPaneHidden = False
        Else
            ViewApplyEx Name:="IBWM Notes", ApplyTo:=1
            detailsPaneHidden = True
        End If
       
    End Sub
    

    The only limitation is that this one will always show the 'IBWM Notes' view in the details pane on the first click (reason: I can't find a way to check if the details pane is visible)

    Hope this helps

    • Marked as answer by KenHolzman Monday, November 24, 2014 3:53 PM
    Friday, November 21, 2014 1:00 PM
  • Toon,

    Incorporate this into your code:

    Sub PaneCheck()
    If ActiveWindow.BottomPane Is Nothing Then
        [do what you want for single pane]
    Else
        [do what you want for split screen]
    End If
    End Sub

    John

    • Marked as answer by KenHolzman Monday, November 24, 2014 2:31 AM
    Friday, November 21, 2014 3:37 PM
  • Hi John,

    Thanks for the suggestion.

    But for some reason the ActiveWindow.BottomPane returns '2' when I use it for the first time after opening MS Project, even if the BottomPane is not visible.

    Can you verify this behaviour and/or give me a reason why it returns that value?

    Thx 

    Saturday, November 22, 2014 10:36 AM
  • Toon,

    Sorry, I can't verify that. I'm using Project 2010 SP2. I closed Project and then re-opened. I immediately went to the VB Editor and displayed the Immediate window where I typed:

    Print ActiveWindow.BottomPane

    The result was as expected, a runtime error of 91 which basically says there is no bottom pane.

    What is your configuration? Also, when you first open Project, go to View/split view group. Is the Details option checked?

    John


    • Edited by John - Project Saturday, November 22, 2014 3:47 PM another thought
    Saturday, November 22, 2014 3:32 PM
  • Hi John,

    I incorporated your code with Toon's and it works perfectly.

    Many thanks for your help.

    I am loving this forum.

    Regards,

    Ken

    Monday, November 24, 2014 2:33 AM
  • Hi Toon

    Thanks for all the effort you put into this. I've combined this version of your code with John's and it works perfectly.

    Sub IBWMShowHideNotes()
    If ActiveWindow.BottomPane Is Nothing Then
        ViewApplyEx Name:="IBWM Notes", ApplyTo:=1
            detailsPaneVisible = False
    Else
        DetailsPaneToggle
            detailsPaneVisible = True
    End If
    End Sub

    Regards

    Ken

    Monday, November 24, 2014 2:37 AM
  • Ken,

    You're welcome and thanks for the feedback. I appreciate you marking my response as the answer but you could also give Toon S credit for his/her effort by marking his/her response as an answer.

    John

    Monday, November 24, 2014 3:47 PM