Publisher Newbie - Object Model In .NET

S

smiller

This might be an idiotic question, but, can I somehow manipulate the
Publisher Object Hierarchy from within a .NET application? If so, could
someone point me in the right direction, (or somwhere thereabouts). If
not....well...just let me down eazy..heh!

Any info will be greatly appreciated.

Thanks
smiller
 
E

Ed Bennett

smiller said:
This might be an idiotic question, but, can I somehow manipulate the
Publisher Object Hierarchy from within a .NET application? If so, could
someone point me in the right direction, (or somwhere thereabouts). If
not....well...just let me down eazy..heh!

Hi,

The Publisher OM is well-accessible from .NET; I've done so myself for a
few add-ins and utilities.

You need to have the .NET framework installed when you install Office
for the PIAs for Office to be installed. These are necessary in order
for the .NET runtime to interact with Publisher's COM interface.

Once that's there, you need to set references to the Microsoft Publisher
Object Library and the Office Object Library.

Once those are in place, you can reference the Publisher object library
from .NET code using Microsoft.Office.Interop.Publisher (where in VBC
code you would simply use Publisher) and Microsoft.Office.Core (where in
VBC code you would use Office). In both cases in VBA code you would not
use a qualifier at all. For example, the VBA code:

Dim aDoc As Document

or the VBC code

Dim aDoc As Publisher.Document

now becomes

Dim aDoc As Microsoft.Office.Interop.Publisher.Document

in VB.NET. (If you use C#/J#/Managed C++/whatever#, you're on your own!)

Note that the PIAs for Publisher are not always well-typed; you will end
up having to use CType in order to avoid compiler warnings.
 
C

Chris Wold

Hi Ed,

I need to automate publisher from VB.NET, I wrote this silly routine, but it
apparently does not launch publisher, i.e. I would like to see "Hello World"
displayed in a new publsher document and have my program start the publisher
application, here is the code:

Public Sub PublisherHelloWorld()
'Create a new instance of Publisher.
Dim publisherApp As Publisher.Application = Nothing
Try
publisherApp = CType(CreateObject("Publisher.Application"),
Publisher.Application)
Dim pbShape As Publisher.Shape
pbShape = publisherApp.ActiveDocument.Pages(1).Shapes.AddTextbox( _
Publisher.PbTextOrientation.pbTextOrientationHorizontal, _
100, _
100, _
100, _
100)
pbShape.TextFrame.TextRange.Text = "Hello World"
Catch ex As Exception
MsgBox(ex.Message)
Finally
publisherApp = Nothing
GC.Collect()
End Try
End Sub

Thanks for your help,
Chris
 
E

Ed Bennett

Chris said:
I need to automate publisher from VB.NET, I wrote this silly routine, but it
apparently does not launch publisher, i.e. I would like to see "Hello World"
displayed in a new publsher document and have my program start the publisher
application, here is the code:

Public Sub PublisherHelloWorld()
'Create a new instance of Publisher.
Dim publisherApp As Publisher.Application = Nothing
Try
publisherApp = CType(CreateObject("Publisher.Application"),
Publisher.Application)

I'm not the world's greatest programmer, but I normally start Publisher with

Dim publisherApp As New Publisher.Application
Dim pbShape As Publisher.Shape
pbShape = publisherApp.ActiveDocument.Pages(1).Shapes.AddTextbox( _
Publisher.PbTextOrientation.pbTextOrientationHorizontal, _
100, _
100, _
100, _
100)
pbShape.TextFrame.TextRange.Text = "Hello World"

You're creating a shape before Publisher's opened a document. Create a
new document with the publisherApp.NewDocument method first.

If this still fails, make sure you have the PIAs installed correctly -
if you haven't used Imports Microsoft.Office.Interop.Publisher, and are
able to simply refer to the Publisher methods using the Publisher
namespace, then they aren't, and you're using dynamically-generated PIAs
(which don't work).
 
C

Chris Wold

Thanks for your help Ed, here is the updated code:

Public Sub PublisherHelloWorld()
'Create a new instance of Publisher and write "Hello World"
Dim pubApp As Publisher.Application = Nothing
Dim pbShape As Publisher.Shape
Try
pubApp = New Publisher.Application
pubApp.ActiveWindow.Visible = True
pbShape = pubApp.ActiveDocument.Pages(1).Shapes.AddTextbox( _
Publisher.PbTextOrientation.pbTextOrientationHorizontal, _
100, _
100, _
100, _
100)
pbShape.TextFrame.TextRange.Text = "Hello World"
Catch ex As Exception
MsgBox(ex.Message)
Finally
pbShape = Nothing
pubApp = Nothing
GC.Collect()
End Try
End Sub

Seems to work without opening or creating a new document, just needed to
make the activewindow visible. I just posted a question about doing catalog
merge, could you take a look at that?

Thanks,
Chris
 
E

Ed Bennett

Chris said:
Seems to work without opening or creating a new document, just needed to
make the activewindow visible. I just posted a question about doing catalog
merge, could you take a look at that?

Glad you sorted it! (And the merge issue too)
 

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