Welcome, Register for free! or Login below:
EduGeek.net RSS Feeds Register FAQ Members Social Groups User Map Calendar Search Today's Posts Mark Forums Read

Go Back   EduGeek.net Forums > Coding and Web Development > Coding
Reply
 
LinkBack Thread Tools Search Thread Language
Sponsored Links
Old 26-06-2008, 04:17 PM   #1
 
park_bench's Avatar
 
Join Date: Nov 2006
Location: Lancashire
Posts: 49
Thanks: 15
Thanked 1 Time in 1 Post
Rep Power: 0 park_bench is an unknown quantity at this point
Send a message via MSN to park_bench
Default 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
  Reply With Quote
Old 26-06-2008, 04:29 PM   #2
 
EduTech's Avatar
 
Join Date: Aug 2007
Location: Birmingham
Posts: 967
uk uk england
Thanks: 19
Thanked 32 Times in 29 Posts
Rep Power: 11 EduTech has a spectacular aura aboutEduTech has a spectacular aura aboutEduTech has a spectacular aura about
Send a message via AIM to EduTech Send a message via MSN to EduTech Send a message via Yahoo to EduTech Send a message via Skype™ to EduTech
Default

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.
  Reply With Quote
Old 26-06-2008, 05:04 PM   #3
 
SYNACK's Avatar
 
Join Date: Oct 2007
Location: Auckland, New Zealand
Posts: 1,702
newzealand
Thanks: 59
Thanked 250 Times in 227 Posts
Blog Entries: 2
Rep Power: 54 SYNACK has much to be proud ofSYNACK has much to be proud ofSYNACK has much to be proud ofSYNACK has much to be proud ofSYNACK has much to be proud ofSYNACK has much to be proud ofSYNACK has much to be proud ofSYNACK has much to be proud ofSYNACK has much to be proud ofSYNACK has much to be proud of
Send a message via MSN to SYNACK
Default

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; 26-06-2008 at 05:07 PM..
  Reply With Quote
Old 26-06-2008, 05:29 PM   #4
 
srochford's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 1,120
uk
Thanks: 1
Thanked 116 Times in 101 Posts
Rep Power: 30 srochford is a splendid one to beholdsrochford is a splendid one to beholdsrochford is a splendid one to beholdsrochford is a splendid one to beholdsrochford is a splendid one to beholdsrochford is a splendid one to behold
Default

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 :-)
  Reply With Quote
Old 30-06-2008, 08:52 AM   #5
 
park_bench's Avatar
 
Join Date: Nov 2006
Location: Lancashire
Posts: 49
Thanks: 15
Thanked 1 Time in 1 Post
Rep Power: 0 park_bench is an unknown quantity at this point
Send a message via MSN to park_bench
Default

Quote:
Originally Posted by SYNACK View Post
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; 30-06-2008 at 02:36 PM..
  Reply With Quote
Reply

Register now for FREE and post messages!


Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Birthday:      
Image Verification
  I agree to forum rules 

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add dummy table to censornet gh256 How do you do....it? 0 10-12-2007 03:24 PM
Time table thegrassisgreener General Chat 35 27-11-2007 05:39 PM
PHP Loop Table Jackd Web Development 2 25-11-2007 01:28 AM
Excel Not Recognizing Cells of Equal Value G_Money Windows 2 21-06-2007 08:33 AM
SQL Table Location G&T mark80 MIS Systems 2 16-05-2007 12:46 PM



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search Thread
Search Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 01:48 AM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Copyright EduGeek.net