BFroeschlKC
Programmer
I'm trying to automate creating a publisher page (a binder cover) from a Publisher "template" document, for each person in a list. The template document "BinderCover Test.pub" has one TextFrame object with the text "Name" in it.
I have some code to automate this template file.
When I run the code, I see this in the Debug Window:
The problem is, when I hit the "stop" line in the code, about a second later, a dialog box appears in the Publisher window:
I can't seem to figure out what is causing this and because this dialog box is open, I can't do anything with Publisher.
Also note that in the Publisher window, the TextFrame has no text in it. If I clear that message BS duplicate the page, the new page has a TextFrame with "####" in it. On the original page, the TextFrame does not have a text area (where you would normally type in some text).
Thus, frustration. Even more frustrating is this code (or a version of it) used to work and would successfully generate a document with many pages with different names filled in.
Does anyone have any idea why this is happening?
I have some code to automate this template file.
Code:
Public Sub PublisherAutomationTest()
Dim PubApp As Object
Dim oDocument As Publisher.Document
Dim oTestDoc As Publisher.Document
Dim oPage As Publisher.page
Dim oShp As Publisher.Shape
Dim oName As cmName
Dim LastPage As Integer
' Initialize Publisher
Set PubApp = CreateObject("Publisher.Application")
Set oDocument = PubApp.Open("C:\Users\bfroe\Documents (local)\Software Development\BinderCover.pub")
oDocument.ActiveWindow.Visible = True
DoEvents
On Error Resume Next
Set oTestDoc = PubApp.ActiveDocument
If Err <> 0 Then
Debug.Print "Looks like Publisher has a dialog box open!"
GoTo GenerateBinders_Exit
End If
On Error GoTo 0
' verify the template
For Each oPage In oDocument.Pages
Debug.Print "Page: " & oPage.Name
For Each oShp In oPage.Shapes
If oShp.Type = pbTextFrame Then
Debug.Print "Text Frame: " & oShp.TextFrame.TextRange.text
If Len(oShp.TextFrame.TextRange.text) = 0 Then
Debug.Print "Bad document"
GoTo GenerateBinders_Exit
End If
End If
Next oShp
Next oPage
Stop
GenerateBinders_Exit:
On Error Resume Next
PubApp.Quit
On Error GoTo 0
Set PubApp = Nothing
Set oDocument = Nothing
Set oTestDoc = Nothing
Set oPage = Nothing
Set oShp = Nothing
Set oName = Nothing
End Sub
When I run the code, I see this in the Debug Window:
Code:
PublisherAutomationTest
Page: Page Title
Text Frame: Name
Text Frame: Retreat title
Text Frame: Binder Cover Date
The problem is, when I hit the "stop" line in the code, about a second later, a dialog box appears in the Publisher window:
I can't seem to figure out what is causing this and because this dialog box is open, I can't do anything with Publisher.
Also note that in the Publisher window, the TextFrame has no text in it. If I clear that message BS duplicate the page, the new page has a TextFrame with "####" in it. On the original page, the TextFrame does not have a text area (where you would normally type in some text).
Thus, frustration. Even more frustrating is this code (or a version of it) used to work and would successfully generate a document with many pages with different names filled in.
Does anyone have any idea why this is happening?