Solved

vba that detects if text is in front of a shape and changes its color or highlite

Posted on 2013-01-16
4
231 Views
Last Modified: 2013-01-29
I add lots of picture to my word documents and would like to have vba change the color of any word with a picture behind it to say yellow. Ist that possible?
0
Comment
Question by:Dov_B
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 38798271
Hi,

This could help

Sub HighlightWordBeforeImage()
Selection.GoTo wdGoToBookmark, , , "\EndOfDoc"
With Selection.Find
  .Text = "^g"
  .Forward = False
  Do While .Execute     'Returns true if the defined text was found.
    Selection.Move Unit:=wdWord, Count:=-3
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    Selection.Range.HighlightColorIndex = wdYellow
    Selection.Collapse
  Loop
End With
End Sub

Open in new window


See example
HighlightWord.doc

This code only works if the word has one punctuation after it (like period, comma, tab, etc.), if not adapt the count at line 7.

Regards
0
 

Author Comment

by:Dov_B
ID: 38799441
Thanks so much for sharing your expertise. My pictures are floating not inline and they float under the text I chose the wrong words when I saind behind the text. if it helps the word on top of the picture has a bookmark in it.
0
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 38799971
Hi,

Could you send a sample of the file or a dummy example?

Regards
0
 

Author Comment

by:Dov_B
ID: 38824340
here is a screanshot of a clipart behind or beneath the text Ineed to be able to make a macro that will change the color or highlite of the text so that it is readable against the background clipart
for-kicking-with.png
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now