Sub Example()
|
|
' Graham Mayor |
|
Application.ScreenUpdating = False |
|
Dim oRng As Range
|
Dim oPara As Paragraph |
Dim strFname As String
|
Const strPath As String = " C:\Path\Folder2\" 'the path with the sub documents
|
For Each oPara In ActiveDocument.Paragraphs |
Set oRng = oPara.Range |
oRng.End = oRng.End - 1 |
If LCase(oRng.Text) Like "part*.docx" Then |
strFname = oRng.Text |
oRng.Text = "" |
If FileExists(strPath & strFname) Then |
oRng.InsertFile strPath & strFname |
End If |
End If |
Next oPara
'CHANGE HEADING 1 |
With ActiveDocument.Content.Find |
.ClearFormatting |
.Style = wdStyleHeading1 |
'The Do...Loop statement repeats a series of actions each time this style is found. |
|
Do While .Execute(Forward:=True, Format:=True) = True |
With .Parent |
.Font.Bold = False |
.Font.Name = "Time New Roman" |
.Font.ColorIndex = wdBlack |
.Font.Size = 16 |
.Font.Underline = True |
.ParagraphFormat.Alignment = wdAlignParagraphLeft |
.ParagraphFormat.SpaceAfter = 6 |
|
End With |
Loop |
End With |
'CHANGE HEADING 2 |
With ActiveDocument.Content.Find |
.ClearFormatting |
.Style = wdStyleHeading2 |
'The Do...Loop statement repeats a series of actions each time this style is found. |
|
Do While .Execute(Forward:=True, Format:=True) = True |
With .Parent |
.Font.Bold = False |
.Font.Name = "Time New Roman" |
.Font.ColorIndex = wdBlack |
.Font.Size = 14 |
.Font.Underline = True |
.ParagraphFormat.Alignment = wdAlignParagraphLeft |
.ParagraphFormat.SpaceAfter = 6 |
|
End With |
Loop |
End With |
'CHANGE NORMAL |
With ActiveDocument.Content.Find |
.ClearFormatting |
.Style = wdStyleNormal |
'The Do...Loop statement repeats a series of actions each time this style is found. |
|
Do While .Execute(Forward:=True, Format:=True) = True |
With .Parent |
.Font.Bold = False |
.Font.Name = "Time New Roman" |
.Font.ColorIndex = wdBlack |
.Font.Size = 12 |
.Font.Underline = False |
.ParagraphFormat.Alignment = wdAlignParagraphJustify |
.ParagraphFormat.SpaceAfter = 6 |
|
End With |
Loop |
End With
'ADD PAGE NUMBER |
With ActiveDocument.Sections(1) |
.Footers(wdHeaderFooterPrimary).PageNumbers.Add _ |
PageNumberAlignment:=wdAlignPageNumberCenter, _ |
FirstPage:=True |
End With |
lbl_Exit: |
Set oPara = Nothing |
Set oRng = Nothing |
Exit Sub |
End Sub |
|
Private Function FileExists(strFullName As String) As Boolean |
|
'strFullName is the name with path of the file to check |
Dim fso As Object |
Set fso = CreateObject("Scripting.FileSystemObject") |
If fso.FileExists(strFullName) Then |
FileExists = True |
Else |
FileExists = False |
End If |
lbl_Exit: |
Exit Function |
End Function |