Jump to content

Recommended Posts

Posted

Hello All,

 

Do you think it would be possible (and relatively simple) to create a Macro using VB that looks through a table (or tables) in a word document and everywhere it finds a symbol, it gives the cell a colour?

 

For example, every cell with a '@' gets coloured red.

 

Thanks in advance everyone.

 

Ben

Posted

I know this can be done, i have seen it done by a friend i used to work with.

 

He was abit of a Macro Genius, will give him a call see if i can get the info for you. :)

 

Regards

 

James.

Posted (edited)

This does it for a single instance, just need some loop code to get it to do the whole lot at once:

 

    Selection.Find.ClearFormatting
   With Selection.Find
       .Text = "@"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   Selection.SelectCell
   With Selection.Cells
       With .Shading
           .Texture = wdTextureNone
           .ForegroundPatternColor = wdColorAutomatic
           .BackgroundPatternColor = wdColorYellow
       End With
   End With

It will search the whole document though, not just cells.

 

This may help to, looping code for find:

http://visualbasic.about.com/library/courses/blecvbai0303.htm

Edited by SYNACK
Posted

You can loop through the collection of tables and then do the search/replace on the contents of each table - I think that would work OK.

 

Is this just a one-off? If so, you can just use ordinary find/replace to specify a colour for the replacement text - this kind of thing is also handy when you want to change (say) 10 point Arial to 12 point Times Bold and you were evil enough to not use styles :-)

Posted (edited)
This does it for a single instance, just need some loop code to get it to do the whole lot at once:

 

Thank you for that - you are right, that works perfectly for a single instance and every time you run it, it finds another cell to colour (until all the symbols have been coloured.

 

I need this to loop now until it has coloured all the cells...

 

as you will have guessed, I am a complete novice at VB and trying to learn it on the fly. I think I need a 'Do While' or 'Do Until' expression, but am unsure of what statement I need to stop it looping.

 

I need something like - Do Until {can't find '@'}

 

Can you suggest how I might do this please?

 

Thanks again.

Edited by park_bench

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...