PDA

View Full Version : Changing Word cell back color by double clicking it



flagmino
08-17-2008, 04:15 AM
How can you write one sub that will change any back color cell of a doc by double clicking it?

macropod
08-17-2008, 04:32 PM
Hi flagmino,

With great difficulty (if at all). That's because Word has no 'event' interface for such things.

If you were using a document protected for forms, though, you could attach an 'on exit' macro to a formfield (eg a checkbox) to shade a cell.

flagmino
08-17-2008, 06:09 PM
I have a table in Word 2003. Some cells have a yellow background and some have a white background. If I select several cells for a cut and paste, how do I only get the yellow cells to be copied?

macropod
08-17-2008, 09:11 PM
Hi flagmino,

This is an entirely different Q to the one you posted before. Are they related in any way? Do the cells occupy whole rows or columns? If not, what's supposed to be done about the cells between the ones you want to copy?

shamsam1
08-17-2008, 11:59 PM
Hi flamingo,

If (CurCell1.Value) = CurCell1.Interior.ColorIndex = 6 Then
"mention where to copy"

end if

or u can also use range to insted of "CurCell1.Value"

flagmino
08-18-2008, 12:08 AM
All the cells are part of one table.

macropod
08-18-2008, 12:12 AM
Hi shamsam1,
If (CurCell1.Value) = CurCell1.Interior.ColorIndex = 6 ThenThat's some strange code. How would you propose to use it to address flagmino's problems - assuming you can get it to work?

macropod
08-18-2008, 12:14 AM
Hi flagmino,
All the cells are part of one table.
Any answers to the Qs I posted? Without those answers, nothing much useful can be done.

shamsam1
08-18-2008, 12:22 AM
he want to copy yellow cells only..so code will work
Sub CopyColor()
Dim rReply As Range, rCell As Range
Dim lCol As Long

Set rReply = Application.InputBox _
(Prompt:="Selct a single cell that has the background color you wish to copy", Type:=8)

lCol = rReply.Interior.ColorIndex

For Each rCell In ActiveSheet.UsedRange
If rCell.Interior.ColorIndex = lCol Then
rCell.EntireRow.Copy Destination:=Sheet2.Range("A65536").End(xlUp)(2, 1)
'the above line was rcell.copy ans was changed to copy the entire row - AAE
End If
Next rCell

End Sub

macropod
08-18-2008, 01:39 AM
Hi shamsam1,

Maybe you hadn't noticed, but this is a WORD vba forum - the code you posted is for Excel and won't work in Word.

I notice too that you didn't make use of 'If (CurCell1.Value) = CurCell1.Interior.ColorIndex = 6 Then' which also wouldn't work, partly because '.Value' isn't a Word cell property and also partly because there's no logical connection between a cell's content and its colour.

flagmino
08-18-2008, 03:07 PM
I am studying Chinese. I have a table of 10 columns by 15 rows. Each cells holds a (master) Chinese character that will not change. The cell background color can either be yellow or white depending on if I successfully identified the character. I quickly end up with a table with only a few yellow cells. I want to select the whole table but only to have the yellow cells characters copied and paste into another application (TTS). The characters never change cells. Only the background color does indicating the characters I have left to study.

macropod
08-18-2008, 04:51 PM
Hi flagmino,

One possible approach is to duplicate the table, then delete the rows with the yellow cells and cut what's left of the table out of the document for pasting.

Another approach would be to copy the table & paste it to the destination first, then delete the excess rows from the pasted copy.

For your purposes, the first approach is more appropriate. That's easy enough, but the "paste into another application (TTS)" bit makes this somewhat trickier. Does that application understand Word tables? If not, what I'd imagine you're really after is the cell contents in a suitable format.