Need to find more info about how to check if the Textbox already exits. If
that is the case, I don't want to add a new one but replace or remove and
then add a new textbox. The problem is that this code is run several times
in the document which means that the document contain several textboxes
laying above each other and I need to avoid that. Many thanks! /Senad
Dim footer As HeaderFooter
Dim mytxtbox As Shape
Set mytxtbox = footer.Shapes.AddTextbox(msoTextOrientationUpward, 0, 0, 12,
70, myrange)
With mytxtbox
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Left = InchesToPoints(0.25)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.top = InchesToPoints(top)
.Line.Visible = msoFalse
.TextFrame.MarginLeft = 1
.TextFrame.MarginRight = 1
.TextFrame.MarginBottom = 1
.TextFrame.MarginTop = 1
.TextFrame.TextRange.Font.Name = "Arial"
.TextFrame.TextRange.Font.Size = 6
.TextFrame.TextRange.Text = sRef
End With
Set myrange = Nothing
Set mytxtbox = Nothing
You can test if the Count property of the specified Shapes collection
is larger than zero; if it is, you know that there is a Shape present.
You can then delete the existing Shape and create your own (or modify
the existing one to suit your needs).

Signature
Stefan Blom
Microsoft Word MVP
> Need to find more info about how to check if the Textbox already exits. If
> that is the case, I don't want to add a new one but replace or remove and
[quoted text clipped - 25 lines]
> Set myrange = Nothing
> Set mytxtbox = Nothing
Senad Isanovic - 21 Feb 2007 14:40 GMT
I have some other Shapes in the doc that should not be removed just the
textbox that is added in the code below. Also, if you have some sample code
available I appreciate if you send it. Thanks!
> You can test if the Count property of the specified Shapes collection
> is larger than zero; if it is, you know that there is a Shape present.
[quoted text clipped - 38 lines]
>> Set myrange = Nothing
>> Set mytxtbox = Nothing
Stefan Blom - 22 Feb 2007 09:29 GMT
You can check only the shapes in a *footer.* For example, the
following code deletes all existing shapes in the primary footer of
the first section:
Dim f As HeaderFooter
Set f = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
Debug.Print f.Range.ShapeRange.Count
If f.Range.ShapeRange.Count > 0 Then
f.Range.ShapeRange.Delete
End If
'Your code here...

Signature
Stefan Blom
Microsoft Word MVP
> I have some other Shapes in the doc that should not be removed just the
> textbox that is added in the code below. Also, if you have some sample code
[quoted text clipped - 42 lines]
> >> Set myrange = Nothing
> >> Set mytxtbox = Nothing