Closing modal form & application

J

J Holtendehouzer

I'm used to Visual Studio 2005, and I've been trying to create a solution in
Publisher using VBA. The differences are frustrating me...

I want to generate instructions for medical patients. The user (a nurse)
needs to be able to type in a name, select an age group and a sex, then check
off several types of instructions (e.g., diabetes, hypertension, etc.).

My solution should then open each publisher document (I used publisher
because the flyer formatting was easier than in word), insert the patient's
name in the right places, and print each one out. Then, I want the documents
to close, and I'd actually like the whole application to close also.

I have everything working--EXCEPT closing the documents I opened, and the
modal user form I'm using as a UI, so I can close the original publisher app.
Any ideas? Am I making sense?

Thanks!
Joe
 
E

Ed Bennett

J said:
I'm used to Visual Studio 2005, and I've been trying to create a solution in
Publisher using VBA. The differences are frustrating me...

Why not write your solution in VS05?
I have everything working--EXCEPT closing the documents I opened, and the
modal user form I'm using as a UI, so I can close the original publisher app.
Any ideas? Am I making sense?

I don't think you're allowed to close the instance of Publisher from
which the form was called, but I think any other instances you've
instantiated can be closed. Writing an application that automates
Publisher from the outside rather than a VBA script inside Publisher
will allow this.
 
J

J Holtendehouzer

Thanks for your reply, Ed. I had the understanding that VS05 with VSTO
doesn't support automating Publisher. Is that incorrect?

I would LOVE to write it in VS05--it's a much more familiar environment for
me. However, I haven't been able to make it work.

Can you point me to a remedial explanation of how to do what I need to do?
(I'm kind of an idiot!)

Thanks in advance,
Joe
 
E

Ed Bennett

J said:
Thanks for your reply, Ed. I had the understanding that VS05 with VSTO
doesn't support automating Publisher. Is that incorrect?

VSTO doesn't support Publisher, but that doesn't stop you from simply
automating Publisher through its COM interface (the same way VBA works,
I think, and the same as writing an add-in).

I'm not aware of any guides for automating Publisher, but it's pretty
simple. Add references to the Publisher Object Library and the Office
Object Library (you MUST have the PIAs for Office installed before doing
this - check your GAC or run through a custom Office Setup and make sure
they're checked - look for '.Net Programmability Support'), and then
create a new instance of Publisher with:

VB:
Dim pbApp As New Microsoft.Office.Interop.Publisher.Application

C# (probably):
Microsoft.Office.Interop.Publisher.Application pbApp = new
Microsoft.Office.Interop.Publisher.Application();

Then declare a Publisher.Document and use the pbApp.Open method to give
it a document. Etc.
 
J

J Holtendehouzer

Ed, you're awesome. Thanks!

Ed Bennett said:
VSTO doesn't support Publisher, but that doesn't stop you from simply
automating Publisher through its COM interface (the same way VBA works,
I think, and the same as writing an add-in).

I'm not aware of any guides for automating Publisher, but it's pretty
simple. Add references to the Publisher Object Library and the Office
Object Library (you MUST have the PIAs for Office installed before doing
this - check your GAC or run through a custom Office Setup and make sure
they're checked - look for '.Net Programmability Support'), and then
create a new instance of Publisher with:

VB:
Dim pbApp As New Microsoft.Office.Interop.Publisher.Application

C# (probably):
Microsoft.Office.Interop.Publisher.Application pbApp = new
Microsoft.Office.Interop.Publisher.Application();

Then declare a Publisher.Document and use the pbApp.Open method to give
it a document. Etc.
 

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