Newbie Here - Need Help With Formatting After a Merge (1 Viewer)

Frank123

Registered User.
Local time
Today, 08:53
Joined
Jun 29, 2016
Messages
31
Hi, I am a novice with VBA and can certainly use some help. I have been losing hair with this. I have a button on a pop up form that merges two Word documents into one Word document. The formatting in both documents are exactly the same. When merged together, the formatting somehow gets screwed up. Mainly, the line spacing increases in some paragraphs which adds more pages to the entire merged document. Is there anyway to correct the formatting using code? Perhaps there is a better way? I would like to continue using VBA. Any help would be greatly appreciated. Here is the code I'm using.

Dim appWord As Word.Application
Dim docDocument As Word.Document
Dim SpecificFolder As Object
Dim SiteFilePath As Object

Set appWord = CreateObject("Word.Application")
With appWord
Set docDocument = .Documents.Add
.Visible = True
.Selection.InsertFile _
FileName:="C:File\MainDoc.docx", _
Link:=False, Attachment:=False
.Selection.InsertNewPage
End With

With docDocument
Set SpecificFolder = Me.SiteFolderName
Set SiteFilePath = Me.SitePathName
appWord.Selection.InsertFile _
FileName:="C:File\Site1.docx"", _
Link:=False, Attachment:=False

End With

Set docDocument = Nothing
Set appWord = Nothing
Set SpecificFolder = Nothing
Set SiteFilePath = Nothing

End Sub
 
I work almost exclusively within an Access environment.

When I have a need to manipulate Word documents (or Excel spreadsheets) from withing Access, I find it easiest to record a macro in Word doing manually what is to be programmed, then copy the VBA generated in the Word module into Access, modifying accordingly.

HTH
 
Great tip...it worked well. Thanks! I also found out that the formatting of merged text can be changed as a deflault by clicking on the very small diagonal arrow located in the lower right hand corner of the Paragraph section on the Home tab in Word. That seemed to help too.
 

Users who are viewing this thread

Back
Top Bottom