PDA

View Full Version : Split Word merge fail help needed... again...



anryo
01-07-2008, 06:52 AM
Hello,
I have found perfect macro for it, but only problem is, as it creates new document for each section - it looses all formatting information (fonts, font sizes, margins etc.).
What needs to be changed in following macro, so it uses formatting from original document?

Macro:
-----------------

Sub Split()
'
' Split Macro
' Macro created 7.01.2008 by user
'
Letters = ActiveDocument.Sections.Count
For Counter = 1 To Letters
Dim myRange As Word.Range
Set myRange = ActiveDocument.Paragraphs(1).Range
myRange.MoveEnd wdCharacter, -1
sName = myRange.Text
myRange.Paragraphs(1).Range.Delete
Docname = "C:\Merge\" & sName & ".doc"
ActiveDocument.Sections.First.Range.Cut
With Documents.Add
.Range.Paste
.SaveAs FileName:=Docname, FileFormat:=wdFormatDocument
.Close
End With
Next
End Sub

melvin74
01-07-2008, 07:12 AM
What exactly is your overall goal.
You say it creates new document for each section.

What are you wanting it to achieve?

anryo
01-07-2008, 07:17 AM
I have merged document with contracts for different clients. I want so, that every contract is in different document. And this macro does it very well. It splits the Word document as needed.
But what I need, that it also preserves the formatting from original document. At the moment it looses all info regarding fonts and etc. and replaces it withj standard 12pt Times New Roman.

melvin74
01-07-2008, 07:34 AM
So is there more than one contract on a page.

Or does each page have one contract and you need to split each page?

anryo
01-07-2008, 07:41 AM
No. Actually every contract is 3 pages. And total 75 contracts.

melvin74
01-07-2008, 07:52 AM
Care to upload sample file?

I am playing around with splitting document as well, maybe can lead each other in right direction.

anryo
01-07-2008, 08:06 AM
It doesn't matter what is the starting document. My macro works only if the document is created with mail merge.
So if yours is also and you don't care about formatting, then you can use the macro I posted before.

TonyJollans
01-07-2008, 02:40 PM
I suspect this is to do with default Paste options - what version of Word are you using?

anryo
01-07-2008, 02:44 PM
It might be about paste options. I'm using Office 2003.
But how can I change document template for creating new documents?

TonyJollans
01-07-2008, 03:16 PM
An easy way may be to disable Smart Cut and Paste - I'm guessing here, of course, - what Word does with formats on pasting is hard to fully control.