+ Reply to Thread
Results 1 to 4 of 4

Create and Use Button Menu using visual Basic in Excel

  1. #1
    Walter L. skinner
    Guest

    Create and Use Button Menu using visual Basic in Excel

    The following code is very simple. All I need to do is figure out how get the
    result of the userform entry from the click event. I apologize if seems to
    easy but I have trouble with userforms and menus getting user data.
    Thanks for Your Help

    Sub test()
    UserForm1.show
    If Me.OptionButton1 = "True" Then
    Debug.Print "Option One has been Selected"
    Else
    Debug.Print "This has failed miserably"
    End If
    End Sub


    Private Sub OptionButton1_Click()
    Dim Sel As String
    Unload Me
    MsgBox ("You Select Buton 1")
    Sel = Me.OptionButton1
    End Sub

    Private Sub OptionButton2_Click()
    Unload Me
    MsgBox ("You Select Buton 2")
    Unload Me
    End Sub

    Private Sub OptionButton3_Click()
    MsgBox ("You Select Buton 3")
    Unload Me
    End Sub


  2. #2
    Bob Phillips
    Guest

    Re: Create and Use Button Menu using visual Basic in Excel

    Walter,

    Are you trying to use a bit of code to show a form and then test what
    control was invoked, from within the original code? If so, I think you have
    a problem, as control will not pass back to that code (the IF statement)
    until the form is closed, either hidden or unloaded,.

    What exactly is the purpose of what you are trying to do.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Walter L. skinner" <[email protected]> wrote in
    message news:[email protected]...
    > The following code is very simple. All I need to do is figure out how get

    the
    > result of the userform entry from the click event. I apologize if seems to
    > easy but I have trouble with userforms and menus getting user data.
    > Thanks for Your Help
    >
    > Sub test()
    > UserForm1.show
    > If Me.OptionButton1 = "True" Then
    > Debug.Print "Option One has been Selected"
    > Else
    > Debug.Print "This has failed miserably"
    > End If
    > End Sub
    >
    >
    > Private Sub OptionButton1_Click()
    > Dim Sel As String
    > Unload Me
    > MsgBox ("You Select Buton 1")
    > Sel = Me.OptionButton1
    > End Sub
    >
    > Private Sub OptionButton2_Click()
    > Unload Me
    > MsgBox ("You Select Buton 2")
    > Unload Me
    > End Sub
    >
    > Private Sub OptionButton3_Click()
    > MsgBox ("You Select Buton 3")
    > Unload Me
    > End Sub
    >




  3. #3
    Walter L. skinner
    Guest

    Re: Create and Use Button Menu using visual Basic in Excel

    Bob: I have VB code that formats and defines a print area. What I need is an
    input from the user telling me which header to use for the printout. I was
    looking to use a list of buttons, wanting the user to select only one of
    them. Then I would use that information to select the header in my code.

    I thought I could envoke a user form displaying the choices and then on a
    "click" event get the user data and transfer it from the private sub "Click"
    to my code.

    I think that explains what I want to do. If that is the wrong approach, I
    would appreciate a good one.

    Thanks

    W. Skinner

    "Bob Phillips" wrote:

    > Walter,
    >
    > Are you trying to use a bit of code to show a form and then test what
    > control was invoked, from within the original code? If so, I think you have
    > a problem, as control will not pass back to that code (the IF statement)
    > until the form is closed, either hidden or unloaded,.
    >
    > What exactly is the purpose of what you are trying to do.
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Walter L. skinner" <[email protected]> wrote in
    > message news:[email protected]...
    > > The following code is very simple. All I need to do is figure out how get

    > the
    > > result of the userform entry from the click event. I apologize if seems to
    > > easy but I have trouble with userforms and menus getting user data.
    > > Thanks for Your Help
    > >
    > > Sub test()
    > > UserForm1.show
    > > If Me.OptionButton1 = "True" Then
    > > Debug.Print "Option One has been Selected"
    > > Else
    > > Debug.Print "This has failed miserably"
    > > End If
    > > End Sub
    > >
    > >
    > > Private Sub OptionButton1_Click()
    > > Dim Sel As String
    > > Unload Me
    > > MsgBox ("You Select Buton 1")
    > > Sel = Me.OptionButton1
    > > End Sub
    > >
    > > Private Sub OptionButton2_Click()
    > > Unload Me
    > > MsgBox ("You Select Buton 2")
    > > Unload Me
    > > End Sub
    > >
    > > Private Sub OptionButton3_Click()
    > > MsgBox ("You Select Buton 3")
    > > Unload Me
    > > End Sub
    > >

    >
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Create and Use Button Menu using visual Basic in Excel

    Why not just a print button to the userform, and then add the code that you
    already have in Test to that button's Click event, without the show?

    Private Sub CommandButton1_Click()
    If Me.OptionButton1 Then
    'set print header 1
    ElseIf Me.OptionButton2 Then
    'set print header 2
    Else
    Debug.Print "This has failed miserably"
    End If
    End Sub

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Walter L. skinner" <[email protected]> wrote in
    message news:[email protected]...
    > Bob: I have VB code that formats and defines a print area. What I need is

    an
    > input from the user telling me which header to use for the printout. I was
    > looking to use a list of buttons, wanting the user to select only one of
    > them. Then I would use that information to select the header in my code.
    >
    > I thought I could envoke a user form displaying the choices and then on a
    > "click" event get the user data and transfer it from the private sub

    "Click"
    > to my code.
    >
    > I think that explains what I want to do. If that is the wrong approach, I
    > would appreciate a good one.
    >
    > Thanks
    >
    > W. Skinner
    >
    > "Bob Phillips" wrote:
    >
    > > Walter,
    > >
    > > Are you trying to use a bit of code to show a form and then test what
    > > control was invoked, from within the original code? If so, I think you

    have
    > > a problem, as control will not pass back to that code (the IF statement)
    > > until the form is closed, either hidden or unloaded,.
    > >
    > > What exactly is the purpose of what you are trying to do.
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Walter L. skinner" <[email protected]> wrote in
    > > message news:[email protected]...
    > > > The following code is very simple. All I need to do is figure out how

    get
    > > the
    > > > result of the userform entry from the click event. I apologize if

    seems to
    > > > easy but I have trouble with userforms and menus getting user data.
    > > > Thanks for Your Help
    > > >
    > > > Sub test()
    > > > UserForm1.show
    > > > If Me.OptionButton1 = "True" Then
    > > > Debug.Print "Option One has been Selected"
    > > > Else
    > > > Debug.Print "This has failed miserably"
    > > > End If
    > > > End Sub
    > > >
    > > >
    > > > Private Sub OptionButton1_Click()
    > > > Dim Sel As String
    > > > Unload Me
    > > > MsgBox ("You Select Buton 1")
    > > > Sel = Me.OptionButton1
    > > > End Sub
    > > >
    > > > Private Sub OptionButton2_Click()
    > > > Unload Me
    > > > MsgBox ("You Select Buton 2")
    > > > Unload Me
    > > > End Sub
    > > >
    > > > Private Sub OptionButton3_Click()
    > > > MsgBox ("You Select Buton 3")
    > > > Unload Me
    > > > End Sub
    > > >

    > >
    > >
    > >




+ 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