Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Publisher / Programming / February 2007

Tip: Looking for answers? Try searching our database.

How programatically append one publisher document to another

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
philipj - 14 Feb 2007 05:35 GMT
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.
Ed Bennett - 14 Feb 2007 09:43 GMT
> 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.

Signature

Ed Bennett - MVP Microsoft Publisher
http://ed.mvps.org

philipj - 14 Feb 2007 19:08 GMT
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.

> > I have 1 publisher document (the "main" document), created from a template,
> > and then content added programatically.
[quoted text clipped - 3 lines]
> If you're looking for a magic ".AppendDocument" function, you're not
> going to find one. It will require significant amounts of manual coding.
Ed Bennett - 15 Feb 2007 01:15 GMT
> 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.

Signature

Ed Bennett - MVP Microsoft Publisher
http://ed.mvps.org

philipj - 19 Feb 2007 23:10 GMT
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.

> > I'm no stranger to coding. I searched through all the VBA help, tried
> > google, couldn't find a starting point.
[quoted text clipped - 4 lines]
> the back burner to give priority to my degree. Creative use of the
> Clipboard and lots of loops is how I was doing it.
Ed Bennett - 19 Feb 2007 23:59 GMT
> 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.

Signature

Ed Bennett - MVP Microsoft Publisher
http://ed.mvps.org

philipj - 20 Feb 2007 02:31 GMT
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

> > I'm using Sendkeys to move the documents to the correct page number
>
[quoted text clipped - 5 lines]
>
> works for me.
Ed Bennett - 20 Feb 2007 11:30 GMT
> For me, subject closed.

Awesome stuff, thanks for posting back :-)

Signature

Ed Bennett - MVP Microsoft Publisher
http://ed.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.