试试- Private Sub CommandButton1_Click()
- Dim Rng, Tb As Table, Arr, F As Boolean
- Set Tb = ThisDocument.Tables(1)
- a1 = Tb.Cell(1, 2).Range.Text
- a1 = Left(a1, Len(a1) - 2)
- Set Rng = GetObject(ThisDocument.Path & "\工作簿1.xlsx")
- Arr = Rng.worksheets("Sheet1").usedrange
- F = False
- For i = 1 To UBound(Arr)
- If Arr(i, 1) = a1 Then
- F = True
- Exit For
- End If
- Next
- If F Then
- Tb.Cell(1, 4).Range.Text = Arr(i, 3) '性别
- Tb.Cell(1, 6).Range.Text = Arr(i, 4) & Arr(i, 5) '年龄+单位
- Tb.Cell(1, 8).Range.Text = Arr(i, 6) 'ABO
- Tb.Cell(1, 10).Range.Text = Arr(i, 7) 'RH
- Tb.Cell(2, 2).Range.Text = Format(Arr(i, 2), "yyyy年m月d日") '日期
- Else
- MsgBox "excel表格中没找到这个人的信息,请先在excel文件里输入再重新导入。"
- End If
- Set Rng = Nothing
- End Sub
复制代码 |