• Word, naming shapes/inlineshapes (Win2K, O2K-pro UK)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Word, naming shapes/inlineshapes (Win2K, O2K-pro UK)

    Author
    Topic
    #386119

    Hi,

    I’ve got a document with multiple shapes on. Some are added through autotexts, some during runtime.
    It seems extremely hard to identify specific shapes in order to adjust and position those.

    Properties and naming possibilities seems also rather limited.
    Then it struck my mind that I’ve heard about “hidden properties”. Here I’m wondering if the shapes and InlineShapes collections also have such ??
    Does anyone know if this is the case – how to access them and potentially also do these 2 items have a “.tag” property….??

    Any guidance are highly appreciated.

    Thanks
    ;o) Henrik

    Viewing 1 reply thread
    Author
    Replies
    • #668654

      As far as I know, Shapes and InlineShapes don’t have properties like Tag. They do have a name, which is read/write, so you can assign a new name if you like, and refer to that name later on.

      If you add a shape in code, you can assign a shape object and refer to that later on:

      Dim sh As Shape
      Set sh = ActiveDocument.Shapes.Add(msoShapeRectangle, 10, 20, 50, 30)

      ‘ other code

      sh.Left = 70
      sh.Top = 60

      • #668688

        Hans,

        I think Word’s Document shapes have a method AddShape rather that Add.

        Set sh = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 10, 20, 50, 30)

        works for me.

        Also to give the shape a permanent name

        Sh.Name = “Name”

        should work.

        Andrew C

        • #668692

          Andrew, you’re right about AddShape. I typed the message directly instead of copying and pasting my test code stupidme.

          Word assigns a Name to a shape like “Box 3”; one can use this, or, as I indicated somewhat obscurely, and you show, assign a name in code.

    • #668854

      Hi Henrik,

      The following macro reports all embedded shapes in a document.

      Sub FindShapes()
      If ActiveDocument.Shapes.Count > 0 Then
      For Each Shp In ActiveDocument.Shapes
      ShapeNames = ShapeNames & Shp.Name & vbCr
      Next Shp
      MsgBox “Found Shapes:” & vbCr & ShapeNames
      End If
      End Sub

      Change

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #668904

        Thanks a lot for your tips – much appreciated.

        I need to specify a little bit here. What I’m adding is a “picture from file…”, but your tips works just as fine – no problem.

        Problem turned out to be to get hold of the picture once inserted…
        Picture is inserted in header/footer and just looping through ‘activedocument.shapes’ returns nothing…
        What I wasn’t aware of initially was, that to be sure to got hold of all shapes when looping through the shapes collection in a document, I need also to loop through eg. ActiveDocument.Headers(wdHeaderFooterPrimary).Shapes or similar footer.

        I didn’t find this obvious, but a lot seems now clearer – thanks.

        ;o) Henrik

    Viewing 1 reply thread
    Reply To: Word, naming shapes/inlineshapes (Win2K, O2K-pro UK)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: