Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub CommandButton1_Click()
  2.     If Selection.Information(wdWithInTable) = True Then
  3.        
  4.         Dim iSelectionRowEnd As Integer
  5.         Dim iSelectionRowStart As Integer
  6.         Dim iSelectionRowCount As Integer
  7.         Dim iSelectionColCount As Integer
  8.        
  9.         Dim tbl As Table
  10.         Set tbl = Selection.Tables(1)
  11.        
  12.         iSelectionRowStart = Selection.Information(wdStartOfRangeRowNumber)
  13.         iSelectionColStart = Selection.Information(wdStartOfRangeColumnNumber)
  14.        
  15.         iSelectionRowCount = Selection.Rows.Count - 1
  16.         iSelectionColCount = Selection.Columns.Count - 1
  17.        
  18.         tbl.Range.Delete
  19.         tbl.Range.Shading.BackgroundPatternColorIndex = 0
  20.        
  21.         For j = 1 To iSelectionColCount
  22.             tbl.Cell(iSelectionRowStart, j + iSelectionColStart).Range.Text = j
  23.             tbl.Cell(iSelectionRowStart, j + iSelectionColStart).Shading.BackgroundPatternColor = RGB(255, 255, 0)
  24.         Next
  25.        
  26.         For i = 1 To iSelectionRowCount
  27.             tbl.Cell(i + iSelectionRowStart, iSelectionColStart).Range.Text = i
  28.             tbl.Cell(i + iSelectionRowStart, iSelectionColStart).Shading.BackgroundPatternColor = RGB(114, 84, 48)
  29.             For j = 1 To iSelectionColCount
  30.                 tbl.Cell(iSelectionRowStart + i, iSelectionColStart + j).Range.Text = i * j
  31.                 If (i + j) Mod 2 Then
  32.                     tbl.Cell(iSelectionRowStart + i, iSelectionColStart + j).Shading.BackgroundPatternColor = RGB(221, 197, 137)
  33.                 Else
  34.                     tbl.Cell(iSelectionRowStart + i, iSelectionColStart + j).Shading.BackgroundPatternColor = RGB(161, 124, 71)
  35.                 End If
  36.             Next
  37.         Next
  38.        
  39.        
  40.     End If
  41. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement