HeaderFooter, AddTextbox

S

Senad Isanovic

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
 
S

Stefan Blom

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).

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 
S

Senad Isanovic

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!
 
S

Stefan Blom

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...


--
Stefan Blom
Microsoft Word MVP


in message
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top