Shading selected selection to 5% programatically?

  • Thread starter StargateFanFromWork
  • Start date
S

StargateFanFromWork

I recorded a test macro just now to shade selected cells to 5%. It's a
macro I'll need enough to keep but the recorded keystrokes include a lot of
garbage I don't need. There may be tables that have different attributes,
etc., than what I recorded the macro with that will get changed. Here's the
recording:

**********************
Sub Macro1()
'
With Selection.Cells
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorGray05
End With
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
End Sub
**********************

I'm guessing here but it seems that the line near the beginning of the code
that is this:

.BackgroundPatternColor = wdColorGray05

is what actually did the shading? Is there a way to have a macro to just
shade rather than all the rest? Pls advise and thanks. :eek:D
 
T

Tony Jollans

Your guess is good and, yes, just remove the bits you don't want:

Sub Macro1()
'
With Selection.Cells
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorGray05
End With
End With
End Sub
 
S

StargateFan

Your guess is good and, yes, just remove the bits you don't want:

Super. :eek:D
Sub Macro1()
'
With Selection.Cells
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorGray05
End With
End With
End Sub

Thank you. I've just emailed myself at the office with that snippet
of code so I have it first thing tomorrow.

Thanks. :eek:D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top