Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    A bit of light relief (Excel 2003)

    Hi

    I am trying to learn VBA and as a bit of light relief I thought I would try this it is verbatum as the book, but it does not work and I can't see why


    Private Sub CommandButton1_Click()
    again:
    With VBAProject.Sheet1.Image1
    Randomize
    .BackColor = QBColor(Int((Rnd * 15) + 1))
    .Top = .Top + 2
    .Left = .Left + 2
    If .Top > 100 Then .Top = 1
    If .Left > 100 Then .Left = 1
    End With
    GoTo again:


    End Sub
    If you are a fool at forty, you will always be a fool

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: A bit of light relief (Excel 2003)

    The code expects the following:
    - The code name of the active sheet - indicated as (Name) in the Properties pane in the Visual Basic Editor - is Sheet1.
    - You have added a command button CommandButton1 on the worksheet from the Control Toolbox.
    - You have double clicked the command button while in design mode, and created the code as posted in the worksheet module.
    - You have added an Image control Image1 on the worksheet from the Control Toolbox.
    Note: the code offers no escape, once it runs, you must press Esc or Ctrl+Break to end it.
    (The colour isn't updated continually when I run the code.)

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: A bit of light relief (Excel 2003)

    Hi Hans

    Thanks for the reply, the code was looking for sheet1 when I had origionaly put it on Sheet5, I have changed the code to With VBAProject.Sheet5.Image1, and it works fine.


    Thanks again

    Braddy

    Incidently Hans when do you sleep? <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    If you are a fool at forty, you will always be a fool

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: A bit of light relief (Excel 2003)

    > when do you sleep?

    At night! <img src=/S/innocent.gif border=0 alt=innocent width=20 height=20>

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: A bit of light relief (Excel 2003)

    tou
    If you are a fool at forty, you will always be a fool

  6. #6
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: A bit of light relief (Excel 2003)

    When he does sleep, one of his many clones answers questions for him <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Steve

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A bit of light relief (Excel 2003)

    And his hands sleep in shifts, usually only four or five of them at any one time. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Alan

Posting Permissions

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