![]() |
|
#3
|
||||
|
||||
|
Maybe something like:
Code:
Sub SplitDoc()
Const strName As String = "Test_" 'the name of the files
Const strPath As String = "C:\Path\" 'the folder to save the files
Dim strDocName As String
Dim oDoc As Document
Dim oRng As Range, oSplit As Range
Dim oNewDoc As Document
Dim strDelim As String: strDelim = ".pa"
Dim Counter As Integer: Counter = 1
Dim strOriginalName As String
Set oDoc = ActiveDocument
oDoc.Save
If oDoc.path = "" Then Beep: GoTo lbl_Exit
strOriginalName = oDoc.FullName
Set oRng = oDoc.Range
Application.ScreenUpdating = False
With oRng.Find
Do While .Execute(FindText:=strDelim, MatchWholeWord:=True, MatchCase:=True)
oRng.Text = ""
Set oSplit = oRng
oSplit.Start = ActiveDocument.Range.Start
Set oNewDoc = Documents.Add(strOriginalName)
oNewDoc.Range.FormattedText = oSplit.FormattedText
strDocName = strPath & strName & _
LTrim$(Str$(Counter)) & ".docx"
oNewDoc.SaveAs2 strDocName
oNewDoc.Close
Counter = Counter + 1
oSplit.Text = ""
oRng.Collapse 0
Loop
End With
oDoc.SaveAs2 strDocName
oDoc.Close wdDoNotSaveChanges
Documents.Open strOriginalName
lbl_Exit:
Set oDoc = Nothing
Set oNewDoc = Nothing
Set oRng = Nothing
Set oSplit = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
| Tags |
| macro, page break, split |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to divide a landscape page into 2 parts | rtcary | Word | 1 | 01-17-2018 12:07 AM |
| One long string of text with ; as the delimiter | Laurie B. | Excel | 1 | 02-28-2015 03:02 AM |
Split file using variable delimiter
|
kramer74 | Word VBA | 7 | 09-01-2014 12:12 AM |
| How do I edit text in Quick Parts? | TommyVincent | Word | 4 | 07-30-2014 01:51 PM |
| divide page into 4 parts | aclark17 | Word | 4 | 01-17-2012 09:04 AM |