Splitting MS Publisher 2010 document into multiple files

2.6k views Asked by At

I want to split a multi-page MS Publisher 2010 document into a set of separate documents, one per page.

The starting document is from a mail-merge, and I am trying to produce a set of numbered and named tickets as PDFs to send to people for an event (this is for a charity). The mail-merge seems to work fine and I can save the merged document and it looks OK with e.g. a list of fifty people giving me a 50-page document.

Ideally the result would be a set of PDFs.

I have tried to create some simple VBA code to do this, but it is not working consistently. If I try this very simple macro below , I get the correct number of documents, but only perhaps 1 or 2 documents with the correct contents out of every five. Most of the documents are completely empty.

Sub splitter()
Dim i As Integer
Dim Source As Document
Dim Target As Document

Set Source = ActiveDocument

For i = 1 To Source.Pages.Count
    Set Target = Documents.Add
    Source.Pages(i).Shapes.Range.Copy
    Target.Pages(1).Shapes.Paste
    Target.SaveAs Filename:="C:\Temp\Ticket_" & i
    Target.Close
    Set Target = Nothing
    Next i

End Sub

I did sometimes get an error that the clipboard is busy, but not always.

Another approach might be to start with the master document and do this looping over the separate documents and fill in the personal details for each person's ticket and directly produce the PDFs. But that seems more complex, and I am not a VB programmer (but been doing C++ etc for 20+ years, so I can program :-) )

A final annoyance is that it seems to keep opening a new Publisher window for each document. It takes a while to then close 50+ copies of publisher, and the laptop starts to crawl...

Please advise how best to get round these issues. I am probably missing something trivial, being a relative VB(A) newbie.

Thanks in advance for any suggestions

1

There are 1 answers

0
Jbjstam On

Try coding something like this:

  1. Open Publisher application (CreateObject()?)
  2. Open Publisher document (doc.Open(filename))
  3. Store the total amount of pages in a global variable (doc.Pages.Count)
  4. Close document (doc.Close())
  5. Loop the following for each page

    • Copy the pub file and rename it to name & "page" & X
    • Open the new pub file
    • Remove all Pages except page X from the pub file
    • doc.Save()
    • doc.Close()

Copying files with VBA is easy, but copying pages in Publisher VBA is quite a hassle, so this should be easier to achieve