+ Reply to Thread
Results 1 to 9 of 9

code for hiding taskbar

Hybrid View

  1. #1
    Registered User
    Join Date
    10-19-2010
    Location
    netherlands
    MS-Off Ver
    Excel 2007, 2010 (Win 7 x64)
    Posts
    10

    Smile code for hiding taskbar

    Hey'all
    This forum has come very handy to me, but now I've found a code that doesn't work for me.

    I'm looking for a macro that can toggle the task bar from showing. With the purpose I can run the excel program in full-screen.

    code i found on this forum:
    Private Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" _
      (ByVal hWnd1&, ByVal hWnd2&, ByVal lpsz1$, ByVal lpsz2$)
     Private Declare Function ShowWindow& Lib "user32" (ByVal hwnd&, ByVal nCmdShow&)
     
     Sub TaskBar_Hide()
     ShowWindow FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString), 0
     End Sub
     Sub TaskBar_Show()
     ShowWindow FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString), 5
     End Sub
    I have windows 7 and excel 2007. For me, this code make's the task bar invisible, but the start button is still visible. and i can't run excel full screen because the space of the task bar is still token.

    (I added a print screen for you to see how the macro works for me)

    Can anybody help me with this?

    Thanks in advance
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: code for hiding taskbar

    Why not just use display full screen
    Option Explicit
    
    Sub ToggleFullScreen()
    Application.DisplayFullScreen = Not Application.DisplayFullScreen
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    10-19-2010
    Location
    netherlands
    MS-Off Ver
    Excel 2007, 2010 (Win 7 x64)
    Posts
    10

    Re: code for hiding taskbar

    full screen won't go really full. you can still see the task bar.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: code for hiding taskbar

    There's an example in this earlier post

  5. #5
    Registered User
    Join Date
    10-19-2010
    Location
    netherlands
    MS-Off Ver
    Excel 2007, 2010 (Win 7 x64)
    Posts
    10

    Re: code for hiding taskbar

    thanks for the quick response roy.

    I can certainly use some part of that code. but it still won't remove the system tray..

  6. #6
    Registered User
    Join Date
    01-20-2011
    Location
    Northampton
    MS-Off Ver
    Excel 2010
    Posts
    3

    Post Re: code for hiding taskbar

    I use Windows 7 too. So far I have not found an elegant method of hiding the Taskbar + the Start Button in this OS (and believe me I have tried). I even used VS Spy utility to try to 'Switch off' the Button according to Class & Caption but to no avail.

    So, I use the following Code to toggle the Taskbar Status. By forcing Excel FullScreen it will then occupy the entire Desktop Window.
    Option Explicit
    
    ' d_taskbar, turns the system taskbar on or off :: FullScreen Excel AddIn
    
    ' SHAppBarMessage
    Private Declare Function _
     SHAppBarMessage Lib "shell32.dll" _
     (ByVal dwMessage As Long, _
      ByRef pData As APPBARDATA) As Long
    
    ' local const
    Private Const ABS_AUTOHIDE As Long = &H1
    Private Const ABM_GETTASKBARPOS As Long = &H5
    Private Const ABM_GETSTATE As Long = &H4
    Private Const ABM_SETSTATE As Long = &HA
    Private Const ABM_SETAUTOHIDEBAR As Long = &H8
    
    ' local type
    Private Type RECT
     left As Long
     Top As Long
     right As Long
     Bottom As Long
    End Type
    
    Private Type APPBARDATA
     cbSize As Long
     hWnd As Long
     uCallbackMessage As Long
     uEdge As Long
     rc As RECT
     lParam As Long
    End Type
    
    ' local vars
    Dim abd As APPBARDATA
    Dim abd_retval, _
        abd_setval As Long
    
    ' AutoHideTaskBar :: sets the appdardata, lParam struct to autohide the system taskbar
    Public Sub HideTaskbar()
    On Error GoTo TaskbarErrorHandler
     Application.EnableCancelKey = xlErrorHandler
      abd_retval = _
       SHAppBarMessage(ABM_GETSTATE, abd)
      abd.lParam = _
       abd_retval Or ABS_AUTOHIDE
      abd_setval = _
       SHAppBarMessage(ABM_SETSTATE, abd)
      Exit Sub
    TaskbarErrorHandler:
     On Error Resume Next
    End Sub
    ' /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ' /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    ' RestoreTaskBar :: restores the autohide system taskbar to a normal state
    Public Sub UnhideTaskbar()
    On Error GoTo TaskbarErrorHandler
     Application.EnableCancelKey = xlErrorHandler
      abd_retval = _
       SHAppBarMessage(ABM_GETSTATE, abd)
      abd.lParam = _
       abd_retval And Not ABS_AUTOHIDE
      abd_setval = _
       SHAppBarMessage(ABM_SETSTATE, abd)
      Exit Sub
    TaskbarErrorHandler:
     On Error Resume Next
    End Sub
    ' /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ' /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    The Error Handler Code is Optional.

    I have written a FullScreen Add-In at:
    http://www.kubiszyn.co.uk

    I am also working on a Free 2003 Add-In which will run along the same lines by toggling the Taskbar Status. When this is finalised I will Post up some Code for re-styling the Excel App + Hiding the Taskbar. Mark Kubiszyn.
    Last edited by Leith Ross; 01-20-2011 at 10:18 PM. Reason: Added Code Tags

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: code for hiding taskbar

    Hello ditisFloris,

    Copy this code into a separate VBA module in your workbook. Call the macro ShowFullScreen in your code. Be sure to call ShowNormalScreen before you close the workbook.
    'Written: January 19, 2011
    'Author:  Leith Ross
    'Summary: Macros to hide and show the Windows Taskbar. Works with Windows '95 - 2003.
    '         Does not work with Vista. There are two additional macros to set the display
    '         to full screen and restore the display to normal.
    
    Private Declare Function FindWindow _
      Lib "User32.dll" Alias "FindWindowA" _
        (ByVal lpClassName As String, _
         ByVal lpWindowName As String) As Long
     
    Private Declare Function SetWindowPos _
      Lib "User32.dll" _
        (ByVal hWnd As Long, _
         ByVal hWndInsertAfter As Long, _
         ByVal X As Long, _
         ByVal Y As Long, _
         ByVal cx As Long, _
         ByVal cy As Long, _
         ByVal uFlags As Long) As Long
     
    Const HWND_TOP As Long = &H0&
    Const SWP_HIDEWINDOW As Long = &H80&
    Const SWP_SHOWWINDOW As Long = &H40&
    
    Sub HideTaskbar()
      Dim Taskbar As Long
        Taskbar = FindWindow("Shell_traywnd", "")
        Call SetWindowPos(Taskbar, HWND_TOP, 0, 0, 0, 0, SWP_HIDEWINDOW)
    End Sub
     
    Sub UnhideTaskbar()
      Dim Taskbar As Long
        Taskbar = FindWindow("Shell_traywnd", "")
        Call SetWindowPos(Taskbar, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW)
    End Sub
    
    Sub ShowFullScreen()
    
          HideTaskbar
          
            With Application
              .DisplayFullScreen = True
              .CommandBars("Worksheet Menu Bar").Enabled = False
            End With
            
            With ActiveWindow
              .DisplayHeadings = False
              .DisplayHorizontalScrollBar = True
              .DisplayVerticalScrollBar = True
              .DisplayWorkbookTabs = True
           End With
          
    End Sub
    
    Sub ShowNormalScreen()
    
          UnhideTaskbar
          
            With Application
              .DisplayFullScreen = False
              .CommandBars("Worksheet Menu Bar").Enabled = True
            End With
            
            With ActiveWindow
              .DisplayHeadings = True
              .DisplayHorizontalScrollBar = True
              .DisplayVerticalScrollBar = True
              .DisplayWorkbookTabs = True
           End With
    
    End Sub
    Last edited by Leith Ross; 01-20-2011 at 10:17 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  8. #8
    Registered User
    Join Date
    10-19-2010
    Location
    netherlands
    MS-Off Ver
    Excel 2007, 2010 (Win 7 x64)
    Posts
    10

    Re: code for hiding taskbar

    Great job! Thank you my friend

  9. #9

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1