Link to home
Start Free TrialLog in
Avatar of DrTribos
DrTribosFlag for Australia

asked on

Macro to find borders around words in a document

Hi I am trying to work with some code by Chris Bottomley
( https://www.experts-exchange.com/questions/26306297/VBA-Word-code-to-find-a-border-around-text.html?anchorAnswerId=34540514#a34540514 ).

I have created a simple document - put a border around a word - run the macro... and was left perplexed  

Sub getBord()
Dim wrd As Object

    For Each wrd In ThisDocument.Words
        If wrd.Borders(wdBorderTop).Visible Then MsgBox "Do Something with " & wrd
    Next
End Sub

Open in new window

... any help appreciated.

Cheers, Steve
Avatar of Flyster
Flyster
Flag of United States of America image

What exactly do you want to happen. If you want to simply count the number of words with borders you can use this code.

Flyster

Sub getBord()
Dim wrd As Object, ct As Integer

ct = 0
    For Each wrd In ThisDocument.Words
        If wrd.Borders(wdBorderTop).Visible Then ct = ct + 1
     Next
     MsgBox "You have " & ct & " word(s) with border(s)"
    
End Sub

Open in new window

Avatar of DrTribos

ASKER

Hi Flyster

Thanks for your reply... perhaps there is something wrong with my copy of Word... I have a test document with 2x words that have borders.  I put the borders around the words using the following procedures.

Word1:
d.click to select word
press border button corresponding to outside border

Word2:
d.click to select word
Format>Borders & Shading>Borders
Apply "Box" border, apply to text > OK

When I run your macro I get:  You have 0 word(s) with border(s)

ouch :-(

Steve
ASKER CERTIFIED SOLUTION
Avatar of DrTribos
DrTribos
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As my solution was not excepted, I believe the points should be refunded.
Reason for accepting own solution: issue solved as stated above