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 / February 2007

Tip: Looking for answers? Try searching our database.

HeaderFooter, AddTextbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Senad Isanovic - 21 Feb 2007 13:03 GMT
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
Stefan Blom - 21 Feb 2007 13:29 GMT
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
 
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.