error setting PageWidth in c#

R

Robert Carsto

Trying to set page width in C# generates an error. I am using Publisher
2003.
here is my sample code segment and the error received. What am I doing
wrong?

Publisher.Application App = new Publisher.Application();

Template = App.Open(@"test.pub", true, true,
Publisher.PbSaveOptions.pbDoNotSaveChanges);

Template.PageSetup.PageWidth = 11 * 8.5;

System.UnauthorizedAccessException: Access is denied.
at Publisher.PageSetup.set_PageWidth(Object RetValue)
at PublisherSample.Class1.Main(String[] args) in
c:\publisher\class1.cs:line 62

The VB example in MSDS is as follows. What am I doing wrong?
Sub SetPageSetupOptions()
With ActiveDocument.PageSetup
.PageHeight = 11 * 72
.PageWidth = 8.5 * 72
End With
End Sub

I am able to set other properties in my document. Its only PageWidth that
fails.
Template.PageSetup.MultiplePagesPerSheet = false;

Template.PageSetup.LeftMargin = (float)Template.PageSetup.LeftMargin ;

Template.PageSetup.TopMargin = (float)Template.PageSetup.TopMargin;

its only PageWidth and PageHeight that fails.
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from Mary
Sauer said:
Go here:
news://msnews.microsoft.com/microsoft.public.publisher.programming

He already has, Mary
No-one there could help him
 
M

Mary Sauer

Hey Ed, Are you admitting failure? I know a simple way to set page width and it
certainly doesn't involve c#.
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from Mary
Sauer said:
Hey Ed, Are you admitting failure? I know a simple way to set page
width and it certainly doesn't involve c#.

As far as I can tell, the OP has a C# program that he wants to use to
automate Publisher. The code he has written technically *should* work, and
does work if written in VBA and executed from within Publisher.
I have very little (read: zero) experience with C#, and have not got the
PIAs installed here to test.
 

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