Jay,
There is definately some disconnect between the BuiltInDialog texture list
selection and what gets applied as shading in the table. Most of the
choices in the list return a positive sequential number, but several 12.5%,
15%, 35%, 45% etc. all return -1. Accrodingly I am using a combination of
an Array with most of the values and a Select Case statement to provide the
rstin in a Function. As a result of this, I was not able to make full use
of the built in dialog to actually reformat each table. If any of those
choice that return -1 are selected then the shading becomes solid 100%.
Below is the complete code that seems to be working correctly in Word2003.
I have left in the statements (commented out) where I tried to use the
Dialog a second time to actually format the tables. I you have time and
interest then maybe you can see something that I was doing wrong.
Thanks.
Public Sub ApplyUniformBordersAndShadingToAllTables()
Dim oTables As Tables
Dim oTable As Table
Dim Title As String
Dim n As Long, i As Long
Dim Shading, Shadow
Dim TopStyle As Long, LeftStyle As Long, BottomStyle As Long
Dim RightStyle As Long, HorizStyle As Long, VertStyle As Long
Dim TL2BRStyle As Long, TR2BLStyle As Long
Dim TopWeight As Long, LeftWeight As Long, BottomWeight As Long
Dim RightWeight As Long, HorizWeight As Long, VertWeight As Long
Dim TL2BRWeight As Long, TR2BLWeight As Long
Dim ForegroundRGB, BackgroundRGB
Dim TopColorRGB, LeftColorRGB, BottomColorRGB
Dim RightColorRGB, HorizColorRGB, VertColorRGB
Dim TL2BRColorRGB, TR2BLColorRGB
Dim LineWeights()
On Error Resume Next
Set oTables = ActiveDocument.Tables
On Error GoTo 0
Title = "Apply Uniform Borders to All Tables"
If Not Selection.Information(wdWithInTable) Then oTables(1).Select
If oTables.Count > 0 Then
If MsgBox("This command applies uniform table borders and shading " & _
"to all tables in the active document." & vbCr & vbCr & _
"Do you want to continue?", vbQuestion + vbYesNo, Title) = vbYes
Then
LineWeights = Array(wdLineWidth025pt, wdLineWidth050pt, _
wdLineWidth075pt, wdLineWidth100pt, _
wdLineWidth150pt, wdLineWidth225pt, _
wdLineWidth300pt, wdLineWidth450pt, _
wdLineWidth600pt)
Err_ReEntry:
With Dialogs(wdDialogFormatBordersAndShading)
If .Display <> 0 Then
Shadow = .Shadow
'Shading = .Shading
Shading = ConvertShading(.Shading)
On Error GoTo Error_Handler
If Shading = "No VBA conversion" Then
Err.Raise vbObjectError + 1
End If
ForegroundRGB = .ForegroundRGB
BackgroundRGB = .BackgroundRGB
LeftStyle = .LeftStyle
RightStyle = .RightStyle
TopStyle = .TopStyle
BottomStyle = .BottomStyle
HorizStyle = .HorizStyle
VertStyle = .VertStyle
TL2BRStyle = .TL2BRStyle
TR2BLStyle = .TR2BLStyle
TopColorRGB = .TopColorRGB
LeftColorRGB = .LeftColorRGB
BottomColorRGB = .BottomColorRGB
RightColorRGB = .RightColorRGB
HorizColorRGB = .HorizColorRGB
VertColorRGB = .VertColorRGB
TL2BRColorRGB = .TL2BRColorRGB
TR2BLColorRGB = .TR2BLColorRGB
On Error Resume Next
TopWeight = .TopWeight
' LeftWeight = .LeftWeight
' BottomWeight = .BottomWeight
' RightWeight = .RightWeight
' HorizWeight = .HorizWeight
' VertWeight = .VertWeight
' TL2BRWeight = .TL2BRWeight
' TR2BLWeight = .TR2BLWeight
TopWeight = LineWeights(.TopWeight)
LeftWeight = LineWeights(.LeftWeight)
BottomWeight = LineWeights(.BottomWeight)
RightWeight = LineWeights(.RightWeight)
HorizWeight = LineWeights(.HorizWeight)
VertWeight = LineWeights(.VertWeight)
TL2BRWeight = LineWeights(.TL2BRWeight)
TR2BLWeight = LineWeights(.TR2BLWeight)
On Error GoTo 0
End If
End With
For Each oTable In oTables
Application.ScreenRefresh
'Count tables - used in message
n = n + 1
With oTable
' .Select
' With Application.Dialogs(wdDialogFormatBordersAndShading)
' .ApplyTo = 2
' .Shadow = Shadow
' .Shading = Shading
' .ForegroundRGB = ForegroundRGB
' .BackgroundRGB = BackgroundRGB
' .LeftStyle = LeftStyle
' .RightStyle = RightStyle
' .TopStyle = TopStyle
' .BottomStyle = BottomStyle
' .HorizStyle = HorizStyle
' .VertStyle = VertStyle
' .TL2BRStyle = TL2BRStyle
' .TR2BLStyle = TR2BLStyle
' .TopColorRGB = TopColorRGB
' .LeftColorRGB = LeftColorRGB
' .BottomColorRGB = BottomColorRGB
' .RightColorRGB = RightColorRGB
' .HorizColorRGB = HorizColorRGB
' .VertColorRGB = VertColorRGB
' .TL2BRColorRGB = TL2BRColorRGB
' .TR2BLColorRGB = TR2BLColorRGB
' .TopWeight = TopWeight
' .LeftWeight = LeftWeight
' .BottomWeight = BottomWeight
' .RightWeight = RightWeight
' .HorizWeight = HorizWeight
' .VertWeight = VertWeight
' .TL2BRWeight = TL2BRWeight
' .TR2BLWeight = TR2BLWeight
' .Execute
' End With
With .Shading
.ForegroundPatternColor = ForegroundRGB
.BackgroundPatternColor = BackgroundRGB
.Texture = Shading
End With
On Error Resume Next
With .Borders(wdBorderLeft)
.LineStyle = LeftStyle
.LineWidth = LeftWeight
.Color = LeftColorRGB
End With
With .Borders(wdBorderRight)
.LineStyle = RightStyle
.LineWidth = RightWeight
.Color = RightColorRGB
End With
With .Borders(wdBorderTop)
.LineStyle = TopStyle
.LineWidth = TopWeight
.Color = TopColorRGB
End With
With .Borders(wdBorderBottom)
.LineStyle = BottomStyle
.LineWidth = BottomWeight
.Color = BottomColorRGB
End With
With .Borders(wdBorderHorizontal)
.LineStyle = HorizStyle
.LineWidth = HorizWeight
.Color = HorizColorRGB
End With
With .Borders(wdBorderVertical)
.LineStyle = VertStyle
.LineWidth = VertWeight
.Color = VertColorRGB
End With
With .Borders(wdBorderDiagonalUp)
.LineStyle = TR2BLStyle
.LineWidth = TR2BLWeight
.Color = TR2BLColorRGB
End With
With .Borders(wdBorderDiagonalDown)
.LineStyle = TL2BRStyle
.LineWidth = TL2BRWeight
.Color = TL2BRColorRGB
End With
On Error GoTo 0
.Borders.Shadow = Shadow
End With
Next oTable
Application.ScreenRefresh
MsgBox "Finished applying borders to " & n & " tables.", vbOKOnly, Title
Else
'Stop if user did not click Yes
Exit Sub
End If
Else
'Stop - no tables are found
MsgBox "The document contains no tables.", vbInformation, Title
End If
Exit Sub
Error_Handler:
If Err.Number = vbObjectError + 1 Then
MsgBox "This texture setting is unavailable for this process.", vbOKOnly,
"Texture Unavailable"
Resume Err_ReEntry
End If
End Sub
Function ConvertShading(ByRef ShadingSel As Long)
Dim lngVar
Dim Shading
MsgBox ShadingSel
Shading = Array(wdTextureNone, wdTextureSolid, wdTexture5Percent, _
wdTexture10Percent, wdTexture20Percent, wdTexture25Percent,
_
wdTexture30Percent, wdTexture40Percent, wdTexture50Percent,
_
wdTexture60Percent, wdTexture70Percent, wdTexture75Percent,
_
wdTexture80Percent, wdTexture90Percent,
wdTextureDarkHorizontal, _
wdTextureDarkVertical, wdTextureDarkDiagonalDown, _
wdTextureDarkDiagonalUp, wdTextureDarkCross, _
wdTextureDarkDiagonalCross, wdTextureHorizontal,
wdTextureVertical, _
wdTextureDiagonalDown, wdTextureDiagonalUp, wdTextureCross,
_
wdTextureDiagonalCross)
Select Case ShadingSel
Case -1
lngVar = InputBox("VBA can not directly convert your texture selection."
& vbCr + vbCr _
& "Please enter the texture percentage value you selected in
the" & _
" space provided.", "Input Texture Percentage")
Select Case lngVar
Case 12.5, 15, 35, 45, 55, 62.5, 65, 85, 87.5, 95
ConvertShading = 10 * lngVar
Case Else
ConvertShading = "No VBA conversion"
End Select
Case Else
ConvertShading = Shading(ShadingSel)
End Select
End Function