Coding Thread, VB code to colour cells in a word table in Coding and Web Development; Hello All,
Do you think it would be possible (and relatively simple) to create a Macro using VB that looks ...
-
26th June 2008, 04:17 PM #1
- Rep Power
- 0
VB code to colour cells in a word table
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
-
-
IDG Tech News
-
26th June 2008, 04:29 PM #2 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.
-
-
26th June 2008, 05:04 PM #3 This does it for a single instance, just need some loop code to get it to do the whole lot at once:
Code:
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...ecvbai0303.htm
Last edited by SYNACK; 26th June 2008 at 05:07 PM.
-
-
26th June 2008, 05:29 PM #4 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 :-)
-
-
30th June 2008, 08:52 AM #5
- Rep Power
- 0

Originally Posted by
SYNACK
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.
Last edited by park_bench; 30th June 2008 at 02:36 PM.
-
SHARE: 
Similar Threads
-
By gh256 in forum How do you do....it?
Replies: 0
Last Post: 10th December 2007, 02:24 PM
-
By thegrassisgreener in forum General Chat
Replies: 35
Last Post: 27th November 2007, 04:39 PM
-
By Jackd in forum Web Development
Replies: 2
Last Post: 25th November 2007, 12:28 AM
-
By G_Money in forum Windows
Replies: 2
Last Post: 21st June 2007, 08:33 AM
-
By mark80 in forum MIS Systems
Replies: 2
Last Post: 16th May 2007, 12:46 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules