这个办法不是最好的办法。但根据楼主要求,我简易制作如下,请参: '* +++++++++++++++++++++++++++++++++++++++ '* Created By I Love You_Word!@ExcelHome 2005-1-13 16:02:44 '仅测试于System: Windows NT Word: 10.0 Language: 2052 '^The Code CopyIn [用户窗体-UserForm1]^' '* -------------------------------------------------------------------------- Dim MyDoc As Document
Private Sub CommandButton1_Click()
Dim strText As String, i As Paragraph, MyStr As String, TF As Boolean, N As Byte
On Error Resume Next
strText = Me.TextBox1
If strText <> "" Then
TF = False
'隐藏方式打开此同一模板同一路径下的指定文档
Set MyDoc = Documents.Open(FileName:=ThisDocument.AttachedTemplate.Path & "\样本文档.doc" _
, Visible:=False)
For Each i In Documents(MyDoc).Paragraphs
N = InStr(i.Range, strText) '提取字符位置
If N > 0 Then
TF = True '赋一个值
MyStr = Documents(MyDoc).Range(i.Range.Start + N + Len(strText), i.Range.End - 2)
' MsgBox MyStr
Selection.InsertAfter MyStr & vbCrLf
Me.TextBox1.SetFocus
End If
Next
If TF = False Then
MsgBox "输入有误!", vbOKOnly + vbInformation
Me.TextBox1 = "" '清空文本框
Me.TextBox1.SetFocus '设置焦点
End If
End If
End Sub
'----------------------
Private Sub CommandButton2_Click()
On Error Resume Next
Unload Me
Documents(MyDoc).Close False '关闭该文档
End Sub
'----------------------
Private Sub UserForm_Activate()
Me.CommandButton1.Default = True
Me.TextBox1.SetFocus
End Sub
'---------------------- |