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 / September 2005

Tip: Looking for answers? Try searching our database.

AutoOpen / Run like macro function in Publisher 2002?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ian McLeish - 19 Sep 2005 23:07 GMT
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
Ed Bennett - 20 Sep 2005 12:40 GMT
> 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?

Signature

Ed Bennett - MVP Microsoft Publisher

Ian McLeish - 21 Sep 2005 20:51 GMT
Ed, thanks, but as I said I am a complete dunce at this, and will gladly
copyany pieces of coding I think might be useful for my purposes. I have no
idea about declaring a variable as a Publisher.Applicication, and please
don't think I am proud to admit that, but it is true. I know that you are
used to helping people that at least have some idea, but if you wouldn't
mind.....

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?

Thanks in anticipation.

Ian

> > I found the shell function in word which can open publisher, and I
> > managed to get a Publisher macro going which would toggle the
[quoted text clipped - 18 lines]
> And Andrew May's technical article series on Publisher at
> http://msdn.microsoft.com/office/understanding/publisher/default.aspx?
Ed Bennett - 21 Sep 2005 21:41 GMT
> Set wrd = GetObject(, "Word.Application")
> wrd.Visible = True
[quoted text clipped - 7 lines]
>
> 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.

Signature

Ed Bennett - MVP Microsoft Publisher


Rate this thread:






 
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.