![]() |
|
#1
|
|||
|
|||
![]()
Hi all
I am new to VBA and new to this forum ("Hello Lawrence") ![]() I have a word document with shapes that I added via the Insert \ Shapes menu entry Some of the shapes are lines, others are rectangles and some are callouts. I even have a picture or two. (Some are in the header area) I wanted a script to run through the shapes and select them. I tried this: Sub FindShapes() Dim doc As Word.Document, rng As Word.Range Dim shp As Word.Shape Set doc = ActiveDocument Set tot = doc.Shapes a = tot.Count For Each shp In doc.Shapes shp.Select Debug.Print shp.Type; shp.ID, shp.Name Next End Sub But it does not find all the shapes. In same cases it may find only one shape. What am I doing wrong? Thank you Lawrence |
#2
|
||||
|
||||
![]()
For a start you are not differentiating between shapes and inline shapes and you need to check all the story ranges where there are shapes e.g. as follows. Note that some of the parameters you want to list are not applicable to inline shapes.
Code:
Sub CheckShapes() Dim oStory As Range Dim oShape As Shape Dim oiShape As InlineShape For Each oStory In ActiveDocument.StoryRanges For Each oShape In oStory.ShapeRange Debug.Print oShape.Type & "; " & oShape.ID & "; " & oShape.Name Next oShape For Each oiShape In oStory.InlineShapes Debug.Print oiShape.Type Next oiShape If oStory.StoryType <> wdMainTextStory Then While Not (oStory.NextStoryRange Is Nothing) Set oStory = oStory.NextStoryRange For Each oShape In oStory.ShapeRange Debug.Print oShape.Type & "; " & oShape.ID & "; " & oShape.Name Next oShape For Each oiShape In oStory.InlineShapes Debug.Print oiShape.Type Next oiShape Wend End If Next oStory Set oStory = Nothing lbl_Exit: Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Thank you very much
I will check this |
![]() |
Tags |
shapes |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
coolio2341 | Word VBA | 6 | 01-31-2019 01:17 PM |
Find This Or That On Line Six of Word Document | StephenRay | Word VBA | 33 | 09-29-2017 02:01 PM |
![]() |
wblock@cnu.edu | Word | 4 | 08-23-2017 06:11 PM |
![]() |
PatrickYork | Word | 1 | 01-05-2012 04:12 AM |
![]() |
bonani | PowerPoint | 1 | 11-26-2009 06:21 PM |