+ Reply to Thread
Results 1 to 4 of 4

right click menu, userform show

  1. #1
    natanz
    Guest

    right click menu, userform show

    i have written a little code to add some new items to the "cells" right
    click menu. the only way i could figure out to use a right click menu
    was to call a second sub that opens the userform. here's what i am
    doing now:

    With Application.CommandBars("Cell").Controls
    With .Add(temporary:=True)
    .Caption = "Respond"
    .OnAction = "module1.ShowForm"
    .Tag = cControlTag
    End With

  2. #2
    Kris
    Guest

    Re: right click menu, userform show

    natanz wrote:
    >
    > Sub ShowForm(FormName As UserForm)
    > FormName.Show
    > End Sub
    >
    > but that doesn't work. Can anyone help?
    >



    The funny thing is that your userform1 doesn't inherit from UserForm
    type and UserForm itself doesn't have Show method

    Sub ShowForm(FormName As Object) should work.



  3. #3
    Tom Ogilvy
    Guest

    Re: right click menu, userform show

    Kris had a good idea, but unfortunately it won't work.

    Here is a tested solution that does work:

    Sub ABCD()

    cControlTag = "ABC"
    With Application.CommandBars("Cell").Controls
    With .Add(temporary:=True)
    .Caption = "Log New RFI(s)"
    .OnAction = "'ShowForm ""LogInNew""'"
    'This is crazy syntax but this is what it takes to call a sub with
    'arguments using .onAction
    .Tag = cControlTag
    .BeginGroup = True
    End With
    End With

    End Sub

    Sub ShowForm(s As String)
    VBA.UserForms.Add(s).Show
    End Sub
    --
    Regards,
    Tom Ogilvy



    "Kris" <[email protected]> wrote in message
    news:[email protected]...
    > natanz wrote:
    > >
    > > Sub ShowForm(FormName As UserForm)
    > > FormName.Show
    > > End Sub
    > >
    > > but that doesn't work. Can anyone help?
    > >

    >
    >
    > The funny thing is that your userform1 doesn't inherit from UserForm
    > type and UserForm itself doesn't have Show method
    >
    > Sub ShowForm(FormName As Object) should work.
    >
    >




  4. #4
    natanz
    Guest

    Re: right click menu, userform show

    thanks for that. I had actually come up with the second solution
    already and was about to post it for the edification of all.
    Unfortunately, i don't really understand it, but i do know it works.
    that just makes it harder to remember every time i come up against the
    same problem.


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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