Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

HasChildShapeRange returns incorrect values

Chris King reported this one in the PowerPoint Newsgroup. This bug affects PowerPoint 2007 and 2003 at least, and may affect earlier versions.

Problem

Although HasChildShapeRange is listed as boolean in the object browser, when HasChildShapeRange is True, its value is 1, not -1. Consequently, IF statements may not work as expected.

To reproduce the problem

To illustrate the problem, put a couple of shapes on a slide and group them, then select one of the group. That makes HasChildShapeRange true. (ChildShapeRange returns the members of a group that are selected.) Insert
the following into a module, and run it:

Sub Play()
   With ActiveWindow.Selection
      If .HasChildShapeRange Then
         Debug.Print "Yes"
      Else
         Debug.Print "No"
      End If
      If .HasChildShapeRange = True Then
         Debug.Print "Yes"
      Else
         Debug.Print "No"
      End If
      If .HasChildShapeRange = False Then
         Debug.Print "No"
      Else
         Debug.Print "Yes"
      End If
      If Not .HasChildShapeRange Then
         Debug.Print "No"
      Else
         Debug.Print "Yes"
      End If
   End With
End Sub

Because HasChildShapeRange is true, the expected output would be

Yes, Yes, No, No

The actual output is

Yes, No, Yes, No

The expression

If .HasChildShapeRange = True Then

evaluates as false because 1 is not equal to -1 (the value of True).

The expression

If Not .HasChildShapeRange Then 

always evaluates as True. (If HasChildShapeRange is False, it equals 0; "Not 0" is -1, or True. If HasChildShapeRange is True, it equals 1; "Not 1" is also True. Only "Not -1" is 0, or False.)

Workaround

Use

If .HasChildShapeRange Then

to test if the expression is True.

Use

If .HasChildShapeRange = False Then

to test if it is False.


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

HasChildShapeRange returns incorrect values
http://www.pptfaq.com/FAQ00858_HasChildShapeRange_returns_incorrect_values.htm
Last update 07 June, 2011
Created: