I have replaced some text with three dots (...) since they contain info I do not want to release
Code:
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(directory)
With wrdDoc
If .Bookmarks.Exists(table_name) Then
With .Bookmarks(table_name).Range
If .Tables.Count > 0 Then
...
Else
...
End If
End With
Else
...
With .Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
.Bookmarks.Add Name:=table_name
With .Tables(1)
With .Cell(1, 1)
.Range.Text = ...
.Select
.Application.Run MacroName:=...
End With
.Cell(1, 2).Range.Text = ...
.Cell(1, 3).Range.Text = ...
With .Cell(2, 1)
.Select
.Range.Bookmarks.Add Name:=...
.Range.Text = ...
End With
With .Cell(2, 2)
.Shading.Texture = wdTextureNone
.Shading.ForegroundPatternColor = wdColorAutomatic
.Shading.BackgroundPatternColor = -721354753
End With
With .Cell(2, 3)
.Shading.Texture = wdTextureNone
.Shading.ForegroundPatternColor = wdColorAutomatic
.Shading.BackgroundPatternColor = -721354753
End With
End With
End If
End With