Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-16
4
Medium Priority
?
241 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 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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 53

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses

971 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