April 9, 2024
Contribute to the Microsoft 365 and Office forum!
Click here to learn more 💡
May 10, 2024
Word Forum Top Contributors:
How do I find shaded text in a large document?
Report abuse
Thank you.
Reported content has been submitted
The following macro will locate all cells with the same background shade as the selected cell and write some text (highlighted) into the cell (so don't test it on your original document!!!!)
Sub Macro1()
Dim oTable As Table
Dim oCell As Cell
Dim iCol As Long
If Selection.Information(wdWithInTable) = True Then
If MsgBox("Is the selected cell the required shade?", vbYesNo) = vbYes Then
iCol = Selection.Cells(1).Shading.BackgroundPatternColorIndex
For Each oTable In ActiveDocument.Tables
For Each oCell In oTable.Range.Cells
If oCell.Shading.BackgroundPatternColorIndex = iCol Then
'Do what you want with the cell here e.g
oCell.Range.Text = "This cell has shading!"
End If
Next oCell
Next oTable
End If
Else
MsgBox "Put the cursor in a cell of the colour you wish to process and run the macro again"
End If
End Sub
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm
Report abuse
Thank you.
Reported content has been submitted
Was this reply helpful?
Sorry this didn't help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
How satisfied are you with this reply?
Thanks for your feedback.
Report abuse
Thank you.
Reported content has been submitted
Was this reply helpful?
Sorry this didn't help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
How satisfied are you with this reply?
Thanks for your feedback.
Put the cursor in a table cell of the required colour shading and run the macro. It will locate each cell from that point in turn and select it so that you can see the content, and then gives you the options to stop or continue to the next. When you wish to resume, leave the cursor in the cell you have stopped at and run the macro again. It will continue from that point.
I have modified it slightly so that you can do almost what you wish (see below).
Sub FindCellColor()
Dim oRng As Range
Dim oTable As Table
Dim oCell As Cell
Dim iCol As Long
If Selection.Information(wdWithInTable) = True Then
If MsgBox("Is the selected cell the required shade?", vbYesNo) = vbYes Then
iCol = Selection.Cells(1).Shading.BackgroundPatternColorIndex
Set oRng = Selection.Range
oRng.End = ActiveDocument.Range.End
For Each oTable In oRng.Tables
For Each oCell In oTable.Range.Cells
If oCell.Shading.BackgroundPatternColorIndex = iCol Then
oCell.Select
If MsgBox("Edit this cell?", vbYesNo) = vbYes Then Exit Sub
End If
Next oCell
Next oTable
End If
Else
MsgBox "Put the cursor in a cell of the colour you wish to process and run the macro again"
End If
End Sub
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm
Report abuse
Thank you.
Reported content has been submitted
Was this reply helpful?
Sorry this didn't help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
How satisfied are you with this reply?
Thanks for your feedback.
Question Info
Last updated August 11, 2023 Views 535 Applies to: