Consulting

Results 1 to 6 of 6

Thread: DisplayFormulaBar Problem

  1. #1
    VBAX Newbie
    Joined
    Apr 2008
    Posts
    3
    Location

    DisplayFormulaBar Problem

    Hi all.

    I have a problem with the Application.DisplayFormulaBar.
    Having the following code:


    [VBA]
    Sub TILPAS_MENU()
    Dim i As Integer
    Dim AllBars As CommandBar
    '
    ' TILPAS_MENU Makro
    '
    With ActiveWindow
    .DisplayHeadings = False
    .DisplayHorizontalScrollBar = False
    .DisplayVerticalScrollBar = False
    End With
    Application.DisplayFormulaBar = False
    i = 0
    Sheets("Opsamling").Range("C1:C50").Clear
    On Error Resume Next
    For Each AllBars In Application.CommandBars
    If AllBars.Visible = True Then
    i = i + 1
    With Sheets("Opsamling")
    .Cells(i, 3) = AllBars.Name
    If AllBars.Name = "Worksheet Menu Bar" Then
    AllBars.Enabled = False
    Else
    AllBars.Visible = False
    End If
    End With
    End If
    Next

    On Error GoTo 0
    End Sub
    Sub NULSTIL_MENU()
    Dim i As Integer
    Dim BarName As String
    '
    ' TILPAS_MENU Makro
    '
    With ActiveWindow
    .DisplayHeadings = True
    .DisplayHorizontalScrollBar = True
    .DisplayVerticalScrollBar = True
    End With

    On Error Resume Next
    With Sheets("Opsamling")
    For i = 1 To WorksheetFunction.CountA(.Columns(3))
    BarName = .Cells(i, 3)
    Application.CommandBars(BarName).Enabled = True
    Application.CommandBars(BarName).Visible = True
    Next i
    i = 1
    End With
    On Error GoTo 0

    Application.CommandBars("Worksheet menu bar").Enabled = True

    Application.DisplayFormulaBar = True
    End Sub
    [/VBA]

    which I respectively called from Open and BeforeClose events to hide and display Toolbars etc. Initial setting is stored in a sheet called "Opsamling".
    All works fine except:

    Application.DisplayFormulaBar = True

    The formulabar won't show. If I run the code manually with F8 the formulabar will show. But I want to run it from a button in the sheet that closes the workbook.

    I've tried a lot of things as setting Application.ScreenUpdating = True, pausing the macro for some seconds, putting Application.DisplayFormulaBar = True in a separate Sub or in the event, call it twice etc.

    Any Ideas

    Regards

    Claus

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Try commenting out the error handlers and see if you can get an idea of what is happening maybe.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Another thought although it is a stretch, since it runs every way except when you use the button......maybe you have something in the button code that may be causing you a problem.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    True Lucas, seems like the code in the command button is exiting before running the desired code, the "On Error Resume Next" in there is masking whatever problem there is in the code.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    VBAX Newbie
    Joined
    Apr 2008
    Posts
    3
    Location
    To Lucas and Simon

    Thank you very much for reply.
    I have tried the suggestions, and have following comments:

    The button in the sheet have the following code:

    Private Sub CommandButton1_Click()
      ActiveWorkbook.Close (False)
    End Sub
    
    In the ThisWorkbook I have the following Events:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Module1.NULSTIL_MENU
    End Sub
     
    Private Sub Workbook_Open()
    Module1.TILPAS_MENU
    End Sub
    
    I have tried commenting out the On Error Resume Next, but I get no errors nor will the FormulaBar display.

    OK, now I have moved the Application.DisplayFormulaBar = True to the CommandButton code, that is:

    Private Sub CommandButton1_Click() Application.DisplayFormulaBar = True
    ActiveWorkbook.Close (False)
    End Sub




    and the problem is solved! Why it won't work from within the Sub I can't figure out.


    Thanks for giving me a lead!




    Regards Claus






  6. #6
    VBAX Newbie
    Joined
    Apr 2008
    Posts
    3
    Location
    ...and I got another experience.

    If I only put Application.DisplayFormulaBar = True in the CommandButton then the formulabar won't show, when closing the workbook/application with the closing X (upper right). That should be obviously.
    If I only put Application.DisplayFormulaBar = True in the closing event then the formularbar won't show, when closing the workbook from the button. That I don't understand.

    So, put Application.DisplayFormulaBar = True in both will do it!

Posting Permissions

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