View Single Post
 
Old 05-12-2024, 04:36 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I think your logic is a little flawed because you aren't being explicit enough to determine which shape you want to address. It appears that it might work if you only ever use it once in a document but you will have several problems if you expect to use it a second time.

Presumably you got that shape name from the shape you saved it into the building blocks, what happens if you have inserted the building block more than once into the document, which instance should this cross-ref go into?
How should the callout be positioned if there is no position info about the photo caption which I assume is already on the page somewhere?
Typically, cross-references point at a caption and it is the caption that might be positioned in a text box sitting under the photo. The cross-reference normally sits somewhere in the text rather than in a shape on the page.

To get you started, have a look at this code. If you run it on a document containing a couple of your shapes you will see that you might have more than one shape with the same name but they will have a unique ID. You can also see that you can place text (or a cross-ref) inside a shape by using its TextFrame.TextRange.
Code:
Sub ShowMe()
  Dim aShp As Shape
  For Each aShp In ActiveDocument.Shapes
    Debug.Print aShp.Name, aShp.ID
  Next aShp
  With ActiveDocument.Shapes(1)
    .TextFrame.TextRange.Text = "Hi Mum"
  End With
End Sub
If this doesn't help, can you post a sample document showing the before/after result of what it is the macro should be able to achieve?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote