|
Option Explicit
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
If StrComp(ContentControl.Tag, "名字", vbTextCompare) = 0 Then
Me.ContentControls(2).Range.Text = GetWeightByName(ContentControl.Range.Text)
End If
End Sub
Private Function GetWeightByName(strFindName As String) As String
Dim tblSource As Word.Table
Dim oCell As Word.Cell
Dim strName As String
Set tblSource = Me.Tables(1)
For Each oCell In tblSource.Columns(1).Cells
strName = Replace$(oCell.Range.Text, Chr$(13) & Chr$(7), Empty)
If StrComp(strName, strFindName, vbTextCompare) = 0 Then
GetWeightByName = Replace$(oCell.Next.Range.Text, Chr$(13) & Chr$(7), Empty)
Exit For
End If
Next
If oCell Is Nothing Then GetWeightByName = "Unknow"
End Function
|
|