I have an excel form that will open up ms word and go to the sixth table and adjust the cell margins. I want the left and right cell margins to be 0.08 for the entire table.
It works perfectly the first time the form is run, but the second time and after it won't do it. Here is my code. Can anyone tell me why this would happen?
Public Sub Table()
Dim wrdApp
Dim wrdDoc
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
Set wrdDoc = wrdApp.Documents.Open("\\FileLocation")
With wrdDoc
'Goes to 6th table and selects it
wrdApp.Selection.Goto wdGoToPage, wdGoToAbsolute, 1
wrdApp.Selection.Goto What:=wdGoToTable, Which:=GoToNext
wrdApp.Selection.Goto What:=wdGoToTable, Which:=GoToNext
wrdApp.Selection.Goto What:=wdGoToTable, Which:=GoToNext
wrdApp.Selection.Goto What:=wdGoToTable, Which:=GoToNext
wrdApp.Selection.Goto What:=wdGoToTable, Which:=GoToNext
wrdApp.Selection.Goto What:=wdGoToTable, Which:=GoToNext
wrdApp.Selection.Tables(1).Select
With wrdApp.Selection.Tables(1)
.TopPadding = InchesToPoints(0)
.BottomPadding = InchesToPoints(0)
.LeftPadding = InchesToPoints(0.08)
.RightPadding = InchesToPoints(0.08)
.Spacing = 0
.AllowPageBreaks = True
.AllowAutoFit = True
End With
End Sub