Sub AddRowtoObstacleTable()
Dim tblNew As Table
Dim rowNew As Row
Dim objCC As ContentControl
ActiveDocument.Unprotect ("casemanagement")
If ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count = 4 Then
Set tblNew = ActiveDocument.Tables(4)
Set rowNew = tblNew.Rows.Add
Selection.Collapse (wdCollapseStart) 'Put the cursor in the first cell of the new row
CurRow = Selection.Information(wdStartOfRangeRowNumber) 'Read the number of the new row
For i = 1 To 5
tblNew.Cell(tblNew.Rows.Count, i).Select 'Select the next cell for processing
If i < 4 Then
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput 'And add a form field
ElseIf i = 4 Then
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlDate)
objCC.DateDisplayFormat = "dd-MMM-yy"
objCC.SetPlaceholderText , , "Click Here"
Else
Dim choice
choice = "Choose"
Set ffield = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormDropDown)
With ffield.DropDown.ListEntries
.Add Name:=choice
End With
MsgBox (ffield.DropDown.ListEntries.Count)
End If
fCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(fCount)
.Name = "col" & i & "row" & CurRow 'Add a unique bookmark name
.Enabled = True 'Enable the field for user entry
.Enabled = False
.TextInput.EditType Type:=wdCalculationText, _
Default:="=Col1Row" & CurRow _
& " + Col2Row" & CurRow _
& " + Col3Row" & CurRow _
& " + Col4Row" & CurRow _
& " + Col5Row" & CurRow, _
Format:=""
End With
Next i
tblNew.Rows.Last.Select
ElseIf ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count = 2 Then
Set tblNew = ActiveDocument.Tables(2)
Set rowNew = tblNew.Rows.Add
Selection.Collapse (wdCollapseStart) 'Put the cursor in the first cell of the new row
CurRow = Selection.Information(wdStartOfRangeRowNumber) 'Read the number of the new row
For i = 1 To 2
tblNew.Cell(tblNew.Rows.Count, i).Select 'Select the next cell for processing
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput 'And add a form field
fCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(fCount)
.Name = "col" & i & "row" & CurRow 'Add a unique bookmark name
.Enabled = True 'Enable the field for user entry
.Enabled = False
.TextInput.EditType Type:=wdCalculationText, _
Default:="=Col1Row" & CurRow _
& " + Col2Row" & CurRow, _
Format:=""
End With
Next i
tblNew.Rows.Last.Select
Else
MsgBox ("Your cursor must be in the Obstacles Table or in the Meeting Participants Table." _
& Chr(13) & "Please place your cursor in one of those two tables and click the button again")
End If
ActiveDocument.Protect wdAllowOnlyFormFields, True, "casemanagement"
End Sub
Sub RemoveRowObstacleTable()
Dim tblNew As Table
Dim rowDel As Row
Dim LastRow
ActiveDocument.Unprotect ("casemanagement")
If ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count = 4 Then
Set tblNew = ActiveDocument.Tables(4)
LastRow = tblNew.Rows.Count
Set rowDel = tblNew.Rows(LastRow)
rowDel.Delete
tblNew.Rows.Last.Select
ElseIf ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count = 2 Then
Set tblNew = ActiveDocument.Tables(2)
LastRow = tblNew.Rows.Count
Set rowDel = tblNew.Rows(LastRow)
rowDel.Delete
tblNew.Rows.Last.Select
Else
MsgBox ("Your cursor must be in the Obstacles Table or in the Meeting Participants Table." _
& Chr(13) & "Please place your cursor in one of those two tables and click the button again")
End If
ActiveDocument.Protect wdAllowOnlyFormFields, True, "casemanagement"
End Sub
Do more with
Selection.FormFields("Dropdown1").DropDown.ListEntries.Add Name:="Item 5"
Selection.FormFields("Dropdown1").DropDown.ListEntries.Add Name:="Item 4"
Selection.FormFields("Dropdown1").DropDown.ListEntries.Add Name:="Item 3"
Selection.FormFields("Dropdown1").DropDown.ListEntries.Add Name:="Item 2"
Selection.FormFields("Dropdown1").DropDown.ListEntries.Add Name:="Item 1"
Premium Content
You need an Expert Office subscription to comment.Start Free Trial