目前,我有一个Word文件,其中包含多个人,并且有详细信息(示例)。我需要将每个人的文件拆分为单个文件。
这是我正在使用的代码,大部分来自我发现的示例,因为我才刚刚开始使用VBA编写单词
基本上,我需要用定界符(个人)分割文件但是每个文件都需要使用位于分隔符正下方的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文档的设置如下:
Personal Name: John Smith EID: Alph4num3r1c (Not a set length as i know of) Details follow on from here Thinking about this I should probably split the document on "Personal"
我的问题恰恰是获取ID号并在另存为功能中使用它。另外,我对split函数的工作方式还不完全了解
目前,我有一个Word文件,其中包含多个人,并且有详细信息(示例)。我需要将每个人的文件拆分为单个文件。这是我正在使用的代码,大部分来自...
Split函数根据定界符将字符串拆分为字符串数组。例如:
如果您的问题仍然有效,我对您搜索的文件名有一些解决方案。我没有检查代码的所有部分(所以我检查了,但是我没有您的原始文档进行完整的分析)。返回文件名-您可以使用以下简单逻辑从新创建的文档中提取名称: