lemonhalls
Technical User
I'm using the code below to merge files from one folder to just one document.
Each file to be merged has a text box at the top of the
document, in it, there are 4 lines of text with different styles and font sizes. First two lines has Arial 12, next two Arial 10 pt. Once I merge them together, the last two lines expand from 10pt to 12pt and is causing the text following to scatter around the and run into another page.
I was thinking of doing a search and replace on font style Arial size 12 to size 10, but it will also pick up the first two lines.
I also tried adding the Arial pt10 style into the after-merge document in case it doesn't pick up styles that don't exist.
How do I get all the text and format to stay exactly the same? Or is there a better approach at this?
Thanks in advance,
S
Sub mergeDoc()
'Dim activeDir As String
activeDir = InputBox _
(Prompt:="Enter the path.", Title:="Path", Default:="U:\")
With Application.FileSearch
.LookIn = activeDir 'folder with old files
End With
'move to the end of the document to insert files
Selection.EndKey Unit:=wdStory, Extend:=wdMove
With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
.FileName = "*.doc"
.MatchTextExactly = False
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Selection.InsertFile FileName:=.FoundFiles(i), Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
margin
Selection.InsertBreak Type:=wdSectionBreakNextPage
Next i
'Remove Final Section Break
Selection.EndKey Unit:=wdStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End With
End Sub
Each file to be merged has a text box at the top of the
document, in it, there are 4 lines of text with different styles and font sizes. First two lines has Arial 12, next two Arial 10 pt. Once I merge them together, the last two lines expand from 10pt to 12pt and is causing the text following to scatter around the and run into another page.
I was thinking of doing a search and replace on font style Arial size 12 to size 10, but it will also pick up the first two lines.
I also tried adding the Arial pt10 style into the after-merge document in case it doesn't pick up styles that don't exist.
How do I get all the text and format to stay exactly the same? Or is there a better approach at this?
Thanks in advance,
S
Sub mergeDoc()
'Dim activeDir As String
activeDir = InputBox _
(Prompt:="Enter the path.", Title:="Path", Default:="U:\")
With Application.FileSearch
.LookIn = activeDir 'folder with old files
End With
'move to the end of the document to insert files
Selection.EndKey Unit:=wdStory, Extend:=wdMove
With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
.FileName = "*.doc"
.MatchTextExactly = False
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Selection.InsertFile FileName:=.FoundFiles(i), Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
margin
Selection.InsertBreak Type:=wdSectionBreakNextPage
Next i
'Remove Final Section Break
Selection.EndKey Unit:=wdStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End With
End Sub