SubAdd table ()'If MsgBox("Do you want to add columns for all tables? ", vbYesNo + vbquestion) = vbyes Then fori =1 toActiveDocument.Tables.CountDimMyTable asTableSetMyTable =activedocument.tables (i) MyTable.Rows.Last.SelectSelection.InsertRowsBelow1selection.collapse Direction:=wdcollapsestartselection.typetext Text:="actual results"selection.moveright Unit:=wdcellselection.typetext Text:="consistent with expected results"selection.moveright Unit:=wdcellselection.typetext Text:="Test Results"selection.moveright Unit:=wdCellSelection.Cells.Split NumRows:=1, numcolumns:=3, mergebeforesplit:=Falseselection.moveright Unit:=wdcellselection.typetext Text:="through"Selection.SelectCellSelection.ParagraphFormat.Alignment=wdAlignParagraphCenterSelection.Cells.VerticalAlignment=wdCellAlignVerticalCenterSelection.SelectCellSelection.ParagraphFormat.Alignment=wdAlignParagraphCenterSelection.Cells.VerticalAlignment=wdcellalignverticalcenterselection.moveright Unit:=wdcellselection.typetext Text:="Defect Number"Selection.SelectCellSelection.ParagraphFormat.Alignment=wdAlignParagraphCenterSelection.Cells.VerticalAlignment=wdcellalignverticalcenterselection.moveright Unit:=wdcellselection.moveright Unit:=wdcellselection.typetext Text:="Notes"selection.moveright Unit:=wdcellselection.moveright Unit:=wdcharacter, count:=3, extend:=wdExtendSelection.Cells.MergeSelection.MoveRight Unit:=wdcellselection.typetext Text:="Test Person"selection.moveright Unit:=wdCellSelection.Cells.Split NumRows:=1, numcolumns:=3, mergebeforesplit:=Falseselection.moveright Unit:=wdcellselection.typetext Text:="XXX"Selection.SelectCellSelection.ParagraphFormat.Alignment=wdAlignParagraphCenterSelection.Cells.VerticalAlignment=wdcellalignverticalcenterselection.moveright Unit:=wdcellselection.typetext Text:="Test Date"Selection.SelectCellSelection.ParagraphFormat.Alignment=wdAlignParagraphCenterSelection.Cells.VerticalAlignment=wdcellalignverticalcenterselection.moveright Unit:=wdcellselection.typetext Text:="2016-4-18"selection.moveleft Unit:=wdcharacter, count:=1selection.moveup Unit:=wdline, count:=1Selection.TypeText Text:="No"Selection.SelectCellSelection.ParagraphFormat.Alignment=wdAlignParagraphCenterSelection.Cells.VerticalAlignment=Wdcellalignverticalcenterselection.movedown Unit:=wdline, count:=1selection.moveright Unit:=wdcharacter, count:=5Selection.SelectCellSelection.ParagraphFormat.Alignment=wdAlignParagraphCenterSelection.Cells.VerticalAlignment=WdcellalignverticalcenterNextMsgBox("Complete")ElseMsgBox("Task Cancellation")End IfEnd Sub
VBA Add Table