Consulting

Results 1 to 3 of 3

Thread: Hide Title Bar of Internet Explorer from excel VBA

  1. #1

    Question Hide Title Bar of Internet Explorer from excel VBA

    Hello All,

    Need help to hide/disable the internet explorer title bar when opening an IE from excel VBA code.

    I am opening a website from excel code, i am trying to hide/disable the internet explorer title bar(Ribbon which appears on the top left, screen short attached to the query) after the page is loaded.

    I couldn't find the exact attribute which can help me in hide/disabling the title bar of the internet explorer.

    Below is the piece of code i am using.

    Sub Button1_Click()
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object


    Set IE = CreateObject("InternetExplorer.Application")
    URL = "https://www.google.com/"
    IE.Visible = True
    IE.MenuBar = 0
    IE.AddressBar = 0
    IE.StatusBar = 0
    IE.Toolbar = 0
    IE.Navigate URL
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
    End Sub
    Attached Images Attached Images

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    To completely remove the TOP HEADER of a worksheet, you need to delve into the API settings.

    Some folks don't recommend messing with the API settings. Sometimes it can create more problems than you want to deal with.

    But, here is code that will do what you are seeking :

    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hWndLock As Long) As Long
    
    
    Private Const GWL_STYLE As Long = (-16) '// The offset of a window's style
    Private Const GWL_EXSTYLE As Long = (-20) '// The offset of a window's extended style
    Private Const WS_CAPTION As Long = &HC00000 '// Title bar bit
    Private Const WS_SYSMENU As Long = &H80000 '// System menu bit
    Private Const WS_THICKFRAME As Long = &H40000 '// Sizable frame bit
    Private Const WS_MINIMIZEBOX As Long = &H20000 '// Minimize box bit
    Private Const WS_MAXIMIZEBOX As Long = &H10000 '// Maximize box bit
    Private Const WS_EX_TOOLWINDOW As Long = &H80 '// Tool Window: small titlebar bit
    Private Const SC_CLOSE As Long = &HF060 'Constant to identify the Close menu item
    '// Set or clear a bit from a style flag
    Private Sub SetBit(ByRef lStyle As Long, ByVal lBit As Long, ByVal bOn As Boolean)
    
    
    If bOn Then
    lStyle = lStyle Or lBit
    Else
    lStyle = lStyle And Not lBit
    End If
    
    
    End Sub
    Public Sub SetStyleHide()
    
    
    Dim lStyle As Long, hMenu As Long
    
    
    'Get the basic window style
    lStyle = GetWindowLong(Application.hwnd, GWL_STYLE)
    
    
    hide_menu
    
    
    If lStyle = 0 Then
    MsgBox "Unable to determine application window handle...", vbExclamation, "Error"
    Exit Sub
    End If
    
    
    '// Build up the basic window style flags for the form adapted to the application window not UF's
    
    
    SetBit lStyle, WS_CAPTION, False
    SetBit lStyle, WS_SYSMENU, False
    SetBit lStyle, WS_THICKFRAME, False
    SetBit lStyle, WS_MINIMIZEBOX, False
    SetBit lStyle, WS_MAXIMIZEBOX, False
    
    
    'Set the basic window styles
    SetWindowLong Application.hwnd, GWL_STYLE, lStyle
    
    
    'Get the extended window style
    lStyle = GetWindowLong(Application.hwnd, GWL_EXSTYLE)
    
    
    
    
    '// Handle the close button
    '// hMenu = GetSystemMenu(Application.hWnd, 1)
    
    
    '// Not wanted - delete it from the control menu
    hMenu = GetSystemMenu(Application.hwnd, 0)
    DeleteMenu hMenu, SC_CLOSE, 0&
    
    
    
    
    'Update the window with the changes
    DrawMenuBar Application.hwnd
    SetFocus Application.hwnd
    
    
    End Sub
    
    
    Public Sub SetStyleShow()
    
    
    Dim lStyle As Long, hMenu As Long
    
    
    'Get the basic window style
    lStyle = GetWindowLong(Application.hwnd, GWL_STYLE)
    
    
    unhide_menu
    
    
    If lStyle = 0 Then
    MsgBox "Unable to determine application window handle...", vbExclamation, "Error"
    Exit Sub
    End If
    
    
    '// Build up the basic window style flags for the form adapted to the application window not UF's
    
    
    SetBit lStyle, WS_CAPTION, True
    SetBit lStyle, WS_SYSMENU, True
    SetBit lStyle, WS_THICKFRAME, True
    SetBit lStyle, WS_MINIMIZEBOX, True
    SetBit lStyle, WS_MAXIMIZEBOX, True
    
    
    'Set the basic window styles
    SetWindowLong Application.hwnd, GWL_STYLE, lStyle
    
    
    'Get the extended window style
    lStyle = GetWindowLong(Application.hwnd, GWL_EXSTYLE)
    
    
    
    
    '// Handle the close button
    '// hMenu = GetSystemMenu(Application.hWnd, 1)
    
    
    '// Not wanted - delete it from the control menu
    'hMenu = GetSystemMenu(Application.hwnd, 0)
    'DeleteMenu hMenu, SC_CLOSE, 0&
    
    
    
    
    'Update the window with the changes
    DrawMenuBar Application.hwnd
    SetFocus Application.hwnd
    
    
    End Sub
    
    
    Sub hide_menu()
    
    
    
    
    With Worksheets("Sheet1")
    
    
    
    
        With ActiveWindow
            .DisplayHorizontalScrollBar = False
            .DisplayVerticalScrollBar = False
        End With
        With Application
            .DisplayFullScreen = True
            .DisplayFormulaBar = False
            .DisplayStatusBar = False
        End With
        With Application
        
            .CommandBars("Full Screen").Visible = False
            .CommandBars("Worksheet Menu Bar").Enabled = False
            .CommandBars("Standard").Visible = False
            .CommandBars("Formatting").Visible = False
        End With
    End With
    End Sub
    
    
    
    
    Sub unhide_menu()
    
    
    
    
    With Worksheets("Sheet1")
    
    
    
    
        With ActiveWindow
            .DisplayHorizontalScrollBar = True
            .DisplayVerticalScrollBar = True
        End With
        With Application
            .DisplayFullScreen = False
            .DisplayFormulaBar = True
            .DisplayStatusBar = True
        End With
        With Application
            .CommandBars("Full Screen").Visible = True
            .CommandBars("Worksheet Menu Bar").Enabled = True
            .CommandBars("Standard").Visible = True
            .CommandBars("Formatting").Visible = True
        End With
    End With
    End Sub
    Attached Files Attached Files

  3. #3
    VBAX Newbie
    Joined
    Nov 2020
    Posts
    2
    Location
    .
    To completely remove the TOP HEADER of a worksheet, you need to delve into the API settings.

    Some folks don't recommend messing with the API settings. Sometimes it can create more problems than you want to deal with.

    But, here is code that will do what you are seeking :
    thanks for that eplanations
    Everything worked
    At directloantransfer.com you could find best possible loan offer in a nick of time. Check it out if you terribly need money

Posting Permissions

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