How programatically append one publisher document to another

P

philipj

I have 1 publisher document (the "main" document), created from a template,
and then content added programatically.
I have 8 other publisher documents, only one of which is to be appended to
the "main" document at any time.

Even manually it's not clear how to do this, but for this project I need to
it programatically.

I'm using Publisher 2003, in winXP sp2.
 
E

Ed Bennett

philipj said:
I have 1 publisher document (the "main" document), created from a template,
and then content added programatically.
I have 8 other publisher documents, only one of which is to be appended to
the "main" document at any time.

If you're looking for a magic ".AppendDocument" function, you're not
going to find one. It will require significant amounts of manual coding.
 
P

philipj

Hi Ed,
I'm no stranger to coding. I searched through all the VBA help, tried
google, couldn't find a starting point. My application (using vb6 sp6) at
this point has content generated over 10 pages, and includes tables of data
(data gathered from PostgreSQL server, using xmlhttp calls to php code), pie
charts, graphs, maps etc.
This constitutes the "main" publisher document.

The other documents that I wanted to selectively append have complete
content, generated manually by others, which changes each quarter. The total
document, for printer and other reasons, has to be sent to the printer as a
single document.

My alternative to a combined Publisher document, is to create a pdf of each
document, then combine the pdfs. Not impossible, but messier than going the
combined Publisher document way, if that is possible.

Any assistance in the overall approach would be appreciated.
 
E

Ed Bennett

philipj said:
I'm no stranger to coding. I searched through all the VBA help, tried
google, couldn't find a starting point.

That's because it hasn't been done before.

I attempted to write a proggy to do this, but had to put the project on
the back burner to give priority to my degree. Creative use of the
Clipboard and lots of loops is how I was doing it.
 
P

philipj

Hi Ed,
I'm well on the way with this.
I'm using Sendkeys to move the documents to the correct page number (this
wasn't simple, either - I eventually found somewhere - I think it was in MS
Access documentation online - that the 2nd parameter only pauses execution
which the keystrokes are executed, not the result of the keystrokes. A delay
must be introduced after Sendkeys to allow the result of the keystrokes to
execute.)
I have programatically positioned the main document to the empty page that I
want to copy to, opened and copied the first page of the 2nd document, and
pasted it shape by shape into the main document. So far, so good.

My problem now is that while I can move to the next empty page in the main
document, I cannot make the 2nd document the active document, so that the
Sendkeys code will execute on it.

my code:
'oDoc is the 1st or main document, 'Report.pub'
'StateDoc is the 2nd document, 'State.pub'

'Ive tried putting in the following delay loop to check
'if/when the 2nd document becomes the active document,
'but it never does.
' Do
' If oApp.ActiveDocument.Name = "State.pub" Then Exit Do
' Call DelayProgram(0.01)
' Loop


i = 0
For Each oStatePage In oStateDoc.Pages
i = i + 1
oStateDoc.ActiveWindow.Activate
Call DelayProgram(SendkeysDelay)
'goto page
SendKeys "{F5}", True 'displays the go to page box
Call DelayProgram(SendkeysDelay) 'SendkeysDelay is delay in seconds
'DelayProgram contains a do..loop which exits after the delay
elapses
'current delay is 0.5 secs, probably far too long
SendKeys CStr(i), True 'enteres the page number
Call DelayProgram(SendkeysDelay)
SendKeys "{ENTER}", True 'hits the [OK] button
Call DelayProgram(SendkeysDelay)

'temp = oStatePage.PageNumber
oStateDoc.ActiveWindow.Activate
Call DelayProgram(SendkeysDelay)
oStatePage.Shapes.SelectAll
Call DelayProgram(SendkeysDelay)

oDoc.ActiveWindow.Activate
Call DelayProgram(SendkeysDelay)
SendKeys "{F5}", True
Call DelayProgram(SendkeysDelay)
SendKeys CStr(Pagenum + i), True
Call DelayProgram(SendkeysDelay)
SendKeys "{ENTER}", True
Call DelayProgram(SendkeysDelay)

j = 1
oStateDoc.ActiveWindow.Activate
Call DelayProgram(SendkeysDelay)
For Each pubShape In oStatePage.Shapes
oStateDoc.ActiveWindow.Activate
Call DelayProgram(SendkeysDelay)
oStatePage.Shapes.Item(j).Copy
Call DelayProgram(SendkeysDelay)

oDoc.ActiveWindow.Activate
Call DelayProgram(SendkeysDelay)
oDoc.Pages(Pagenum + i).Shapes.Paste
Call DelayProgram(SendkeysDelay)
j = j + 1
Next
Next
end code:

Any thoughts on this?

regards,
Phil.
 
E

Ed Bennett

philipj said:
I'm using Sendkeys to move the documents to the correct page number

....Why are you using SendKeys to change page?

Try:

[Document].ActiveView.ActivePage = [Document].Pages(x)

works for me.
 
P

philipj

Hi Ed,
That's just what I needed - don't know how I missed that one.
Particularly since the help in Publisher is so good.

Here's the final version:

***my code**********************************

i = 0
For Each oPage In oStateDoc.Pages
'goto page
i = i + 1
oStateDoc.ActiveView.ActivePage = oStateDoc.Pages(i)

oPage.Shapes.SelectAll
Call DelayProgram(1)

oDoc.ActiveView.ActivePage = oDoc.Pages(Pagenum + i)

j = 1
For Each pubShape In oPage.Shapes
oPage.Shapes.Item(j).Copy
Call DelayProgram(1)
oDoc.Pages(Pagenum + i).Shapes.Paste
Call DelayProgram(1)
j = j + 1
Next
Next

***end my code ********************************

For me, subject closed.
thanks again.
regards,
Phil

Ed Bennett said:
philipj said:
I'm using Sendkeys to move the documents to the correct page number

....Why are you using SendKeys to change page?

Try:

[Document].ActiveView.ActivePage = [Document].Pages(x)

works for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top