AutoOpen / Run like macro function in Publisher 2002?

I

Ian McLeish

Longwinded story, so here goes.....
I am an optician, using a recall program by a company now vanished.
This program has the capability to print information from it's database to
word document templates, using mail merge fields. By adding an autoopen macro
to these .dot files I could get them to open, print and then close
automatically. What has this to do with Publisher? The information inserted
by word is then printed onto a record card which is pre-printed from a
publisher document.

It occurred to me that I might kill "two birds with one stone" if I could
perform the mail merge and print the record card at the same time- without
pre-printing the blank record cards.

My problems are.

The recall software will only call one of four files called GOS1a.dot to
GOS4a.dot.

I found the shell function in word which can open publisher, and I managed
to get a Publisher macro going which would toggle the mergefields in
Publisher, print and then close publisher. But I would like to be able to
autorun this macro, so that whenever the word macro opens publisher it
automatically does the above. I cannot find an autorun function in Publisher,
but wondered if I could use word to get round that? I couldn't get publisher
to open the required document either, though the macro worked when the
document was open, but I am sure I will be able to sort that one out myself.
It is a shame Publisher doesn't have a record macro function, like word, as
even a complete novice like me learned a fair bit (though it was a while
ago), just by recording macros, then viewing their text listing. I tried to
record a macro of opening a doc in word and then sort of copying the macro
to Publisher, which failed miserably!

As I said, I am a complete novice.
Could anyone suggest a way round this?

Thanks in anticipation,

Ian
 
E

Ed Bennett

Ian McLeish said:
I found the shell function in word which can open publisher, and I
managed to get a Publisher macro going which would toggle the
mergefields in Publisher, print and then close publisher. But I would
like to be able to autorun this macro, so that whenever the word
macro opens publisher it automatically does the above.

There are two ways you can do this.
You can either automate Publisher from Word, or you can automate Publisher
from Publisher.

To automate Publisher from Word, you add a reference to the Publisher
object library in your Word project. Then you declare a new variable as a
Publisher.Application. Then you work with the automation in that.
To automate Publisher from Publisher, you handle the Open event in the
particular document you're using.
I would tend to automate Publisher from Word in this circumstance, as this
way all your code is consolidated in one place.

I take it you have already found the Publisher OM documentation at
c:\Program Files\Microsoft Office\Office10\1033\VBAPB10.CHM?
And Andrew May's technical article series on Publisher at
http://msdn.microsoft.com/office/understanding/publisher/default.aspx?
 
E

Ed Bennett

Ian McLeish said:
Set wrd = GetObject(, "Word.Application")
wrd.Visible = True
wrd.Documents.Open "C:\My Documents\Temp.doc"
Set wrd = Nothing

I found this code, which opens word and then a document. I (obviously
wrongly)thought I might just be able to replace word.application with
publisher.application and then point it at my record card.pub, to at
least get it to open, but alas...

Am I completely wrong in my above assumption?

Not completely.
I haven't used GetObject to create a new Publisher application, I would
normally instead use

Dim pubApp As New Publisher.Application

But I see no reason why the code you quote above shouldn't work in that
context.

Publisher's object model, however, is different from Word's in many ways.
In Publisher, to open a new document, you instead use the code:

pubApp.Open(FileName, ReadOnly, AddToRecentFiles, SaveChanges,
OpenConflictDocument)

FileName Required String. The name of the publication (paths are
accepted).
ReadOnly Optional Boolean. True to open the publication as read-only.
Default is False.
AddToRecentFiles Optional Boolean. True (default) to add the file name to
the list of recently used files at the bottom of the File menu.
SaveChanges Optional PbSaveOptions. Specifies what Publisher should do if
there is already an open publication with unsaved changes.
OpenConflictDocument Optional Boolean. True to open the local conflict
publication if there is an offline conflict. Default is False.

This is documented in (and copied and pasted from) the Publisher VBA help
file that I listed in my previous post.

As the Open method returns a Document object, I would advise that you
declare a variable with which to reference this new document, as it will
save you fiddling around with ActiveDocument.

Dim pubApp As New Publisher.Application
Dim pubDocument As Publisher.Document
Set pubDocument = pubApp.Open("C:\My Documents\Temp.pub")

Note that you will have to add a reference to the Publisher Object Model in
your Word IDE to be able to do this.
 

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