0

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

4

1 回答 1

0

尝试编写如下代码:

  1. 打开 Publisher 应用程序(CreateObject()?)
  2. 打开 Publisher 文档 (doc.Open(filename))
  3. 将总页数存储在全局变量 (doc.Pages.Count) 中
  4. 关闭文档 (doc.Close())
  5. 为每个页面循环以下内容

    • 复制 pub 文件并将其重命名为name & "page" & X
    • 打开新的 pub 文件
    • 从 pub 文件中删除除页面 X 之外的所有页面
    • doc.Save()
    • doc.Close()

用VBA复制文件很简单,但是在Publisher VBA中复制页面比较麻烦,所以这应该更容易实现

于 2015-09-22T21:04:21.610 回答