我有一个包含多人及其详细信息的 Word 文件。
我需要将此文件拆分为每个人的单个文件。
这是代码,大部分来自我找到的示例。
我需要按分隔符(个人)拆分文件。
每个文件都需要通过位于分隔符下方的 ID 号来命名。
Sub SplitNotes (delim As String)
Dim sText As String
Dim sValues(10) As String
Dim doc As Document
Dim arrNotes
Dim strFilename As String
Dim Test As String
Dim I As Long
Dim X As Long
Dim Response As Integer
arrNotes = Split(ActiveDocument.Range, delim)
Response = MsgBox("This will split the document into " & UBound(arrNotes) + 1 & " sections.Do you wish to proceed?", 4)
If Response = 7 Then Exit Sub
For I = LBound(arrNotes) To UBound(arrNotes)
If Trim(arrNotes(I)) <> "" Then
X = X + 1
Set doc = Documents.Add
doc.Range = arrNotes(I)
'Find "EID: "
doc.Range.Find.Text = "EID: "
'Select whole line
Selection.Expand wdLine
'Assign text to variable
sText = Selection.Text
'Remove spaces
sText = Replace(sText, " ", "")
'Split string into values
sValues = Split(sText, ":")
strFilename = "Testing"
doc.SaveAs ThisDocument.Path & "\" & strFilename & Format(X, "Agent")
doc.Close True
End If
Next I
End Sub
Sub Test()
'delimiter
SplitNotes "Name:"
End Sub
Word文档设置如下:
个人的 姓名:约翰·史密斯 EID:Alph4num3r1c(不是我所知道的设定长度) 详细信息从这里开始
我的问题是获取 ID 号并在另存为功能中使用它。
我对拆分功能的工作原理没有完全了解。