+ Reply to Thread
Results 1 to 8 of 8

Message box [how it works??]

  1. #1
    furbiuzzu
    Guest

    Message box [how it works??]

    i've inserted a toggle button in my excel sheet (sheet "ratings").
    i want, by clickin' on it, a message box to appear.
    the text of this message box is allocated on a cell of a different
    sheet (named: labels) of the same excel file.

    if i put these lines on togglebutton code:

    Private Sub ToggleButton1_Click()
    text = Range("labels!A980").Value
    MsgBox (text)
    End Sub

    it doesn't work!

    if i write a macro named 'totali'
    and associate it to toggle button code it works. why??

    here's the effective code that works :

    Sub totali()
    Dim testo As String
    text = Range("labels!A980").Value
    MsgBox (text)
    End Sub

    Private Sub ToggleButton1_Click()
    Application.Run "My.T.y.M.xls!totali"
    End Sub

    thanks !


  2. #2
    Bob Phillips
    Guest

    Re: Message box [how it works??]

    Because you have used a button from the Forms toolbar. The Click macro
    applies to a control toolbox button.

    --
    HTH

    Bob Phillips

    "furbiuzzu" <[email protected]> wrote in message
    news:[email protected]...
    > i've inserted a toggle button in my excel sheet (sheet "ratings").
    > i want, by clickin' on it, a message box to appear.
    > the text of this message box is allocated on a cell of a different
    > sheet (named: labels) of the same excel file.
    >
    > if i put these lines on togglebutton code:
    >
    > Private Sub ToggleButton1_Click()
    > text = Range("labels!A980").Value
    > MsgBox (text)
    > End Sub
    >
    > it doesn't work!
    >
    > if i write a macro named 'totali'
    > and associate it to toggle button code it works. why??
    >
    > here's the effective code that works :
    >
    > Sub totali()
    > Dim testo As String
    > text = Range("labels!A980").Value
    > MsgBox (text)
    > End Sub
    >
    > Private Sub ToggleButton1_Click()
    > Application.Run "My.T.y.M.xls!totali"
    > End Sub
    >
    > thanks !
    >




  3. #3
    furbiuzzu
    Guest

    Re: Message box [how it works??]

    thanks 4 answering.

    but i'm a newenewnewbie in programming with VB.
    there's not a way to disply the msgbox i want with just one click on a
    toggle button ?


  4. #4
    Harald Staff
    Guest

    Re: Message box [how it works??]

    Rightclick the button, choose "assign macro" and assign the Totali macro to
    it.

    HTH. Best wishes Harald

    "furbiuzzu" <[email protected]> skrev i melding
    news:[email protected]...
    > thanks 4 answering.
    >
    > but i'm a newenewnewbie in programming with VB.
    > there's not a way to disply the msgbox i want with just one click on a
    > toggle button ?
    >




  5. #5
    Dave Peterson
    Guest

    Re: Message box [how it works??]

    I think you used the correct togglebutton for your code (from the Control
    toolbox toolbar, right?).

    But I think your code is confusing excel.

    Try this:

    Option Explicit
    Private Sub ToggleButton1_Click()
    Dim myText As Variant
    myText = Worksheets("labels").Range("a980").Value
    MsgBox myText
    End Sub

    (Text is a property that VBA uses. I try to stay away from them--that confuses
    me--even if VBA can figure it out.)

    But this line:

    text = Range("labels!A980").Value

    has an unqualifed range object. In a general module, that range syntax would
    work ok. But under a worksheet module, excel thinks you mean a range on the
    sheet that owns the code (and Labels is a different sheet, right?).

    You could have used something like this, too:
    myText = Application.Range("labels!A980").Value

    But I like this first way lots more:
    myText = Worksheets("labels").Range("a980").Value

    I find it easier to read later on (when I'm correcting my other mistakes).

    furbiuzzu wrote:
    >
    > i've inserted a toggle button in my excel sheet (sheet "ratings").
    > i want, by clickin' on it, a message box to appear.
    > the text of this message box is allocated on a cell of a different
    > sheet (named: labels) of the same excel file.
    >
    > if i put these lines on togglebutton code:
    >
    > Private Sub ToggleButton1_Click()
    > text = Range("labels!A980").Value
    > MsgBox (text)
    > End Sub
    >
    > it doesn't work!
    >
    > if i write a macro named 'totali'
    > and associate it to toggle button code it works. why??
    >
    > here's the effective code that works :
    >
    > Sub totali()
    > Dim testo As String
    > text = Range("labels!A980").Value
    > MsgBox (text)
    > End Sub
    >
    > Private Sub ToggleButton1_Click()
    > Application.Run "My.T.y.M.xls!totali"
    > End Sub
    >
    > thanks !


    --

    Dave Peterson

  6. #6
    furbiuzzu
    Guest

    Re: Message box [how it works??]

    really thanks

    myText =3D Worksheets("labels").Range("a9=AD80").Value

    is what i meant to write.

    it works, and , as you saud, is very easy to read.

    sorry for my newbie questions!


  7. #7
    Dave Peterson
    Guest

    Re: Message box [how it works??]

    Nothing to be sorry about.

    Glad you got it working.

    furbiuzzu wrote:
    >
    > really thanks
    >
    > myText = Worksheets("labels").Range("a9*80").Value
    >
    > is what i meant to write.
    >
    > it works, and , as you saud, is very easy to read.
    >
    > sorry for my newbie questions!


    --

    Dave Peterson

  8. #8
    Bob Phillips
    Guest

    Re: Message box [how it works??]

    Hi Harald,

    I thought he said he had already done that!

    Bob

    "Harald Staff" <[email protected]> wrote in message
    news:[email protected]...
    > Rightclick the button, choose "assign macro" and assign the Totali macro

    to
    > it.
    >
    > HTH. Best wishes Harald
    >
    > "furbiuzzu" <[email protected]> skrev i melding
    > news:[email protected]...
    > > thanks 4 answering.
    > >
    > > but i'm a newenewnewbie in programming with VB.
    > > there's not a way to disply the msgbox i want with just one click on a
    > > toggle button ?
    > >

    >
    >




+ 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