Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Shapes, ShapeRanges (Word 2003)

    Hi All,

    can anyone shed any light on the difference between a ShapeRange and the Shapes Collection when referring to the shapes in a Footer in VB? I have for example:

    oSec.Footers(2).Shapes.Count = 4
    oSec.Footers(2).Range.ShapeRange.Count = 2

    and i don't understand the difference - unless 2 of the Shapes in the Shapes collection are InlineShapes, which aren't included in the ShapeRange collection?

    The reason I am having trouble with all of this is because I insert a shape into a footer (the "different first page footer" index 2 in the Footers collection for the first section of the document) and then i try to remove it again. When I come to remove it, apparently it isn't there. I was looping through the ShapeRange collection.

    I add the picture using:

    Dim newLogo as Shape
    Set newLogo = oSec.Footers(2).shapes.AddPicture(FileName:=Me.lbl SubsLogoPath)

    which is NOT an Inline shape.

    If I then try to locate it for later deleting, I can do it OK if I loop through the Shapes collection searching for its known name, but it fails if I loop through the footer's "ShapeRange" collection... even though it should be in both.

    The most confusing thing is why there are apparently 4 shapes in the Shapes collection for the footer, when on my screen there are clearly only 2...

    Can anyone confirm my understanding of the difference?

    cheers

  2. #2
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: Shapes, ShapeRanges (Word 2003)

    I have found a couple of sentences in the Help, but they seem rather conflicting to me :-(

    "The Shapes property, when applied to a HeaderFooter object, returns all the Shape objects found in all the headers and footers in the document."

    &

    "This example displays a count of all the shapes in the primary header and footer of the first section of the active document.

    MsgBox ActiveDocument.Sections(1). Headers(wdHeaderFooterPrimary).Shapes.Count"

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

    Re: Shapes, ShapeRanges (Word 2003)

    Very confusingly, the Shapes collection of *any* header consists of *all* shapes in *all* headers and footers in the document. So if your document has two sections whose headers are not linked to each other, and if the header of the first section contains 2 shapes and the header of the second section 1 shape, ActiveDocument.Sections(n).Headers(wdHeaderFooterP rimary).Shapes.Count will return 3, whether n = 1 or n = 2.

    But the ShapeRange collection of the Range of a header contains only the shapes that actually belong to that header. So in the above example, ActiveDocument.Sections(1).Headers(wdHeaderFooterP rimary).Shapes.Count will return 2 and ActiveDocument.Sections(2).Headers(wdHeaderFooterP rimary).Shapes.Count will return 1.

    The same holds for footers.

  4. #4
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: Shapes, ShapeRanges (Word 2003)

    Thanks.. i had just reached that conclusion from using the de######.

    Anyway, I just found my error and it was in a totally unrelated part of the code and I could've spent years trying to find it. Luckily I just spotted an uninitialised function return value.. oops

Posting Permissions

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