Consulting

Results 1 to 15 of 15

Thread: Solved: How can I enable a right click on this code?

  1. #1
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location

    Solved: How can I enable a right click on this code?

    How can I write a code to enable user to perform a right click prior of copy and pasting data to sheet cells... Correct me if I'm wrong due to below code I guess disabled the right click option in the workbook upon opening.

    [vba]
    Private Sub Workbook_Activate()
    Dim oCB As CommandBar
    For Each oCB In Application.CommandBars
    oCB.Enabled = False
    Next oCB
    mFormulaBar= Application.DisplayFormulaBar
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False

    Private Sub Workbook_Deactivate()
    Dim oCB As CommandBar
    For Each oCB In Application.CommandBars
    oCB.Enabled = True
    Next oCB
    Application.DisplayFormulaBar = mFormulaBar
    Application.DisplayFormulaBar = True
    Application.DisplayStatusBar = True

    End Sub
    [/vba]
    Above code was taken from xld ...
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba] Private mFormulaBar

    Private Sub Workbook_Activate()
    Dim oCB As CommandBar

    For Each oCB In Application.CommandBars
    If oCB.Name "Cell" Then
    oCB.Enabled = False
    End If
    Next oCB

    mFormulaBar = Application.DisplayFormulaBar
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False
    End Sub

    Private Sub Workbook_Deactivate()
    Dim oCB As CommandBar

    For Each oCB In Application.CommandBars
    oCB.Enabled = True
    Next oCB

    Application.DisplayFormulaBar = mFormulaBar
    Application.DisplayFormulaBar = True
    Application.DisplayStatusBar = True
    End Sub [/vba]

  3. #3
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    once again thnks xld for that quick response however all of the toolbars came visible giving that if statement..
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by jammer6_9
    ... however all of the toolbars came visible giving that if statement..
    I am not sure if you are saying it worked or not.

  5. #5
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    right click works on the worksheet but all of the toolbars came visible which i have hidden. On my worksheet I have made "My Toolbar"...

    Quote Originally Posted by xld
    I am not sure if you are saying it worked or not.
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Do you mean that you hide toolbars in a workbook, activate this workbook and all bars get hidden, but when you reactivate the first worksheet, your hidden bars suddenly become visible?

  7. #7
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Yes from the code that I have taken from you, I was able to hide all the Toolbars as I wanted to happen when I activate a workbook... The only problem that I wanted to fixed is "Enable a Right Click" on the worksheet... Through the code that you recently gave
    [vba]Private Sub Workbook_Activate()
    Dim oCB As CommandBar

    For Each oCB In Application.CommandBars
    If oCB.Name "Cell" Then
    oCB.Enabled = False
    End If
    Next oCB

    mFormulaBar = Application.DisplayFormulaBar
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False
    End Sub
    [/vba]

    Right click on the worksheet is successful but the Toolbars was enabled.

    Quote Originally Posted by xld
    Do you mean that you hide toolbars in a workbook, activate this workbook and all bars get hidden, but when you reactivate the first worksheet, your hidden bars suddenly become visible?
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I am sorry, but you are totally losing me.

    When I run this code, all toolbars except right-click are disabled.

    One sentence you say ... I was able to hide all the Toolbars as I wanted

    Another you say ... but the Toolbars was enabled

  9. #9
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    So sorry xld pls... Let me refresh...

    1. Code below -->All Toolbars is disabled
    ***The only problem is I can not perfrom a "Right Click"???
    [vba]Private Sub Workbook_Activate()
    Dim oCB As CommandBar
    For Each oCB In Application.CommandBars
    oCB.Enabled = False
    Next oCB
    mFormulaBar= Application.DisplayFormulaBar
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False

    End Sub
    [/vba]

    2. Code below --> Right Click is OK...
    ***But Toolbars are enabled...???
    [vba]Private Sub Workbook_Activate()
    Dim oCB As CommandBar

    For Each oCB In Application.CommandBars
    If oCB.Name "Cell" Then
    oCB.Enabled = False
    End If
    Next oCB

    mFormulaBar = Application.DisplayFormulaBar
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False
    End Sub


    [/vba]
    What I want to happen is
    1. Toolbars will be hidden in the Workbook or Worksheet
    2. Right Click is enabled in the worksheet

    Thanks for your patience xld...

    Quote Originally Posted by xld
    I am sorry, but you are totally losing me.

    When I run this code, all toolbars except right-click are disabled.

    One sentence you say ... I was able to hide all the Toolbars as I wanted

    Another you say ... but the Toolbars was enabled
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    We seem to have lost some code in transposition

    [vba] If oCB.Name "Cell" Then
    [/vba]
    should be

    [vba] If oCB.Name <> &quot;Cell&quot; Then [/vba]

  11. #11
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Still no right click on the worksheet
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Now you are changing your tune. You now say still, before you said you had the right-click, but all toolbars were still enabled.

  13. #13
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Please have a look on my workbook code... All I want is
    1. Hide all Toolbars &
    2. a Right Click enabled on the Worksheet...

    Thanks
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is not the code I gave

    [vba]

    Private mFormulaBar
    Private Sub Workbook_Activate()
    Dim oCB As CommandBar

    For Each oCB In Application.CommandBars
    If oCB.Name <> "Cell" Then
    oCB.Enabled = False
    End If
    Next oCB

    mFormulaBar = Application.DisplayFormulaBar
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False
    AddNewToolBar


    End Sub

    Private Sub Workbook_Deactivate()
    Dim oCB As CommandBar

    For Each oCB In Application.CommandBars
    oCB.Enabled = True
    Next oCB

    Application.DisplayFormulaBar = mFormulaBar
    Application.DisplayFormulaBar = True
    Application.DisplayStatusBar = True
    DeleteToolbar

    End Sub
    [/vba]

  15. #15
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Thanks xld. My workbook now work as I wanted. I was able to perfrom a right click on the cells as well as hide all the tool bars.

    tnx tnx tnx...
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

Posting Permissions

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