Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If.....End If problem (I think) (VBA/Powerpoint/2000)

    I'm having a bit of a problem with the following code.

    Sub MySub()
    On Error Resume Next

    If ActiveWindow.Selection.ShapeRange().Name ="Bar" Then
    Call MyBarCode(myVarients)

    Else If
    Call NoBarCode(myVarients)
    End If
    End Sub.

    Basically, If an objected that has been prenamed "Bar" is selected, then it should do something to it, and if it's not selected it does something else. The problem is, when "Bar" isn't selected on the slide, the code is still running MyBarCode bit of the code.

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

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

    Re: If.....End If problem (I think) (VBA/Powerpoint/2000)

    If nothing is selected, the line

    If ActiveWindow.Selection.ShapeRange().Name ="Bar" Then

    causes an error. But since you have On Error Resume Next, the next line will be executed!

    Your Else If is invalid since there is no condition after it. Try this version:

    Sub MySub()
    Dim sh As Shape
    On Error Resume Next
    Set sh = ActiveWindow.Selection.ShapeRange(1)
    If Not sh Is Nothing Then
    If sh.Name = "Bar" Then
    Call MyBarCode(myVarients)
    Exit Sub
    End If
    End If
    Call NoBarCode(myVarients)
    End Sub

  4. #3
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If.....End If problem (I think) (VBA/Powerpoint/2000)

    Many thanks for the explaination Hans. I didn't realise I was using the Else If incorrectly.

    many thanks

Posting Permissions

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