Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

How to determine name of newly added shape

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dcuthill - 23 Nov 2004 23:31 GMT
I add a shape to a document using the following code. How do I identify this
newly added shape in order to refer to it later? Can I name it - if so how?
Or can I get it's index and later refer to it by an index number or is the
index a dynamic number that change as other shapes are added to the document.

  Set oShape = Rng.InlineShapes.AddOLEObject _
                  (ClassType:="Excel.Chart.8", _
                   FileName:="", _
                   LinkToFile:=False, _
                   DisplayAsIcon:=False)
Doug Robbins - 23 Nov 2004 23:43 GMT
I assume that you have dimmed oShape as a Shape.   That being the case, just
refer to oShape.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

>I add a shape to a document using the following code. How do I identify
>this
[quoted text clipped - 9 lines]
>                    LinkToFile:=False, _
>                    DisplayAsIcon:=False)
dcuthill - 24 Nov 2004 07:29 GMT
Let's say I add the shape, save and close the document and then open it again
later. How do I know which shape was tghe one I added in the previous session
- especially if I have a number of such shapes? Can I not give the shape a
specific name when it is inserted?

> I assume that you have dimmed oShape as a Shape.   That being the case, just
> refer to oShape.
[quoted text clipped - 12 lines]
> >                    LinkToFile:=False, _
> >                    DisplayAsIcon:=False)
Doug Robbins - 24 Nov 2004 11:12 GMT
Try assigning a bookmark to it.  But YOU will have to remember the name of
the bookmark

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Let's say I add the shape, save and close the document and then open it
> again
[quoted text clipped - 21 lines]
>> >                    LinkToFile:=False, _
>> >                    DisplayAsIcon:=False)
Jean-Guy Marcil - 24 Nov 2004 14:43 GMT
dcuthill was telling us:
dcuthill nous racontait que :

> Let's say I add the shape, save and close the document and then open
> it again later. How do I know which shape was tghe one I added in the
> previous session - especially if I have a number of such shapes? Can
> I not give the shape a specific name when it is inserted?

As Doug wrote, with inline shapes the best bet is to use a bookmark. Set a
range to the inserted shape and assign a bookmark, use a constant in the
code for the bookmark name.

Otherwise, if you can work with floating shapes, the Name property is handy.
I have done this many times and it works like a charm later, as in:

'_______________________________________
Const ShapeName As String = "MyShapeName"

Dim oShape As Shape
Dim MyRange As Range

Set MyRange = Selection.Paragraphs(1).Range
Set oShape = ActiveDocument.Shapes.AddShape(Type:=msoShapeRectangle, _
       Left:=50, Top:=50, Width:=100, Height:=200, Anchor:=MyRange)

oShape.Name = ShapeName

ActiveDocument.Shapes(ShapeName).Select
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

dcuthill - 24 Nov 2004 18:25 GMT
I have tried to implement your suggestions. This code is giving an error when
I try to assign the name to the shape "method or data member not found". Any
ideas?

  Const ShapeName As String = "MyShapeName"
  Dim xlApp As Excel.Application
  Dim oWordDoc As Word.Document
  Dim oShape As Word.InlineShape
  Dim oGraphChart As Excel.Chart
  Dim oWorkbook As Excel.Workbook
  Dim oSheet As Excel.Worksheet
  Dim Rng As Word.Range
  Dim TabCnt As Long
  Dim i As Long
 
  WindowUpdating (False)  'to freeze the screen
 
  Set oWordDoc = ActiveDocument
  TabCnt = oWordDoc.Tables.Count
   
  For i = 1 To TabCnt Step 4
 
  Set Rng = ActiveDocument.Tables(i).Range
  Rng.Copy
  Rng.Collapse wdCollapseEnd
  Rng.InsertAfter "" & vbCrLf
  Rng.Collapse wdCollapseEnd
 
  Set oShape = Rng.InlineShapes.AddOLEObject _
                  (ClassType:="Excel.Chart.8", _
                   FileName:="", _
                   LinkToFile:=False, _
                   DisplayAsIcon:=False)
                   
  oShape.Name = ShapeName   <==== Method or data member not found
 

> dcuthill was telling us:
> dcuthill nous racontait que :
[quoted text clipped - 25 lines]
> ActiveDocument.Shapes(ShapeName).Select
> '_______________________________________
Jean-Guy Marcil - 24 Nov 2004 19:05 GMT
dcuthill was telling us:
dcuthill nous racontait que :

> I have tried to implement your suggestions. This code is giving an
> error when I try to assign the name to the shape "method or data
> member not found". Any ideas?

Having a long day? :-)

Here is what I wrote :
<quote>
As Doug wrote, with inline shapes the best bet is to use a bookmark. Set a
range to the inserted shape and assign a bookmark, use a constant in the
code for the bookmark name.

Otherwise, if you can work with floating shapes, the Name property is handy.
I have done this many times and it works like a charm later, as in:
<unquote>

I meant that the Name property is not available to inline shapes, which is
what you are using.
Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

dcuthill - 24 Nov 2004 19:13 GMT
Okay, okay, okay ... now I understand.

> dcuthill was telling us:
> dcuthill nous racontait que :
[quoted text clipped - 17 lines]
> I meant that the Name property is not available to inline shapes, which is
> what you are using.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.