VBA: Turn On/Off Scroll Bars

January 4th, 2005 | Categories: VBA | Tags:

You can toggle scrollbars On or Off using a macro:

Turn On Scrollbars:

Sub TurnOnScroll()
    With ActiveWindow
        .DisplayHorizontalScrollBar = True
        .DisplayVerticalScrollBar = True
    End With
End Sub

Turn Off Scrollbars:

Sub TurnOffScroll()
    With ActiveWindow
        .DisplayHorizontalScrollBar = False
        .DisplayVerticalScrollBar = False
    End With
End Sub
  1. Michael
    May 21st, 2005 at 08:43
    Reply | Quote | #1

    How can I switch between on and off of both scrollbars ?

    Sub ToggHorizBarl()
    ‘ This example toggles the horizontal scroll bar of the actual window
    Dim winTemp As Window
    Set winTemp = ActiveWindow
    winTemp.DisplayHorizontalScrollBar = _
    Not winTemp.DisplayHorizontalScrollBar
    End Sub

  2. Mark
    May 21st, 2005 at 08:56
    Reply | Quote | #2

    Is this a trick question, or did I misunderstand it?

    The example toggles both scroll bars on or off….

    To toggle just the Horizontal scrollbar, delete the Vertical code,, and vice versa.

    This just toggles the vertical bar:

    Sub ToggVertOFF()
       With ActiveWindow
            .DisplayVerticalScrollBar = False
       End With
    End Sub
    Sub ToggVertON()
       With ActiveWindow
            .DisplayVerticalScrollBar = True
       End With
    End Sub