Solved

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

Posted on 2013-01-16
4
236 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 50

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 50

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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) …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

679 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