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

Tip: Looking for answers? Try searching our database.

Adding new pages to an existing document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Otto - 20 Jan 2005 14:37 GMT
With the following code I am trying to add new pages to a new document. But
all attempts fail:

Private Sub cmdSetupPubDoc_Click()
 Dim sMsg As String
 Dim lngPageID As Long
 Dim story01 As Publisher.Story
 Dim page01 As Publisher.Page
 Dim page02 As Publisher.Page
 Dim page03 As Publisher.Page
 Dim page04 As Publisher.Page
 Dim textframe01 As Publisher.TextFrame
 Dim shpTextBox1 As Publisher.Shape
 Dim shpTextBox2 As Publisher.Shape
 On Error GoTo eh

 Set oApp = New Publisher.application
 Set oDoc = oApp.NewDocument
 oApp.ActiveWindow.Visible = True

 With oDoc
   .SaveAs "XYZ1.pub", pbFilePublication, True
   .LayoutGuides.MarginBottom = 60
   .LayoutGuides.MarginTop = 30
   .LayoutGuides.MarginLeft = 30
   .LayoutGuides.MarginRight = 30
   .LayoutGuides.Columns = 3
   '.LayoutGuides.Rows = 9
   .ViewTwoPageSpread = True
   .ActiveView.Zoom = pbZoomWholePage
' the following line does not work:
'    .Pages.Add 1, 1
 End With
   
 Set page01 = oApp.ActiveDocument.Pages(1)
' the following line does not work:
'  oApp.ActiveDocument.Pages.Add 1, 2
 
' the following line does not work, either:    
  lngPageID = oApp.ActiveDocument.Pages.Add(Count:=1, After:=1).PageID
  ...
  ...

ende:
    exit sub
eh:
    msgbox err.description
    resume ende
end sub  

Can someone help me, please?

Thanks in advance.
Paul
Ed Bennett - 21 Jan 2005 21:26 GMT
> With the following code I am trying to add new pages to a new
> document. But all attempts fail:

What does the MsgBox of err.description tell you?
Also, what version of Publisher are you using?  Are you using Visual Basic 6
to automate it?

Signature

Ed Bennett - MVP Microsoft Publisher

Paul Otto - 22 Jan 2005 09:53 GMT
Hi Ed,
thank you for your reply.
Well, the messagebox says: "Automation Error -2147417851 (80010105)"
and, yes, I am automating Publisher2003 from VB6.
Greetings
Paul

> > With the following code I am trying to add new pages to a new
> > document. But all attempts fail:
>
> What does the MsgBox of err.description tell you?
> Also, what version of Publisher are you using?  Are you using Visual Basic 6
> to automate it?
Paul Otto - 02 Apr 2005 09:35 GMT
I am still waiting for someone to help me solve this problem!!!
Paul

> > With the following code I am trying to add new pages to a new
> > document. But all attempts fail:
>
> What does the MsgBox of err.description tell you?
> Also, what version of Publisher are you using?  Are you using Visual Basic 6
> to automate it?
Ed Bennett - 02 Apr 2005 13:41 GMT
> I am still waiting for someone to help me solve this problem!!!
> Paul

OK, I'm at a loss, but out of desperation I'll suggest what I always do when
I have an untrappable error

Comment out all your error-handling code, see if the error still occurs.  If
it does, note which line the program breaks on (will be highlighted in
yellow when execution halts due to the error).

Signature

Ed Bennett - MVP Microsoft Publisher

zackb - 26 Apr 2005 19:01 GMT
What is it exactly that you are referring to?  Apparently Ed knows that code
to which you refer, but I cannot find it.  In another newsgroup perhaps??

Anyway, error handling is a serious issue and should be dealt with very
carefully.  You need to know what will cause an error and where.  If you
don't know, set up some watches and then step through your code (VBE | F8).

Try to stay away from On Error Resume Next statements, as they can be
hazardous; sometimes they are a necessity though.  You can re-route errors
with the On Error Goto errHandler type statements (with a matching
"errHandler:" line statement where the redirect will take the code).
Another way to check for errors is to (coupled with an error aversion) check
for the Err property ...

If Err Then 'or If Err <> 0 Then
   'your error handling code here
   Msgbox "You have an error!" & vbcrlf & vbcrlf & _
   "Error: " & Err.number & vbcrlf & _
   "Description: " & Err.description
Else
   'no error here!
   Msgbox "No errors!"
End If

Many ways exist to handle errors; most (imho) vary dependent upon the
structure and purpose of your code.  Each must be handled in their own
unique way.

HTH, and regards,
Zack Barresse

>> I am still waiting for someone to help me solve this problem!!!
>> Paul
[quoted text clipped - 5 lines]
> If it does, note which line the program breaks on (will be highlighted in
> yellow when execution halts due to the error).
zackb - 26 Apr 2005 19:06 GMT
Hello Paul,

Sorry, did not see your code.  (Doh!)  How about something like this ..

Set page02 = oApp.ActiveDocument.Pages.Add 1, 2

Does that help?

Regards,
Zack Barresse

>> I am still waiting for someone to help me solve this problem!!!
>> Paul
[quoted text clipped - 5 lines]
> If it does, note which line the program breaks on (will be highlighted in
> yellow when execution halts due to the error).
Ed Bennett - 26 Apr 2005 20:00 GMT
zackb <zackb@portofmorrow.com> was very recently heard to utter:
> Hello Paul,
>
> Sorry, did not see your code.  (Doh!)  How about something like this
> ..
> Set page02 = oApp.ActiveDocument.Pages.Add 1, 2

In VBA, if the method comes after the = sign, then the arguments have to be
enclosed in brackets.

i.e. Set page02 = oApp.ActiveDocument.Pages.Add(1, 2)

Signature

Ed Bennett - MVP Microsoft Publisher

zackb - 26 Apr 2005 20:03 GMT
Yes, I forget that when I write shorthand vba..  uh, oops.  LOL!

Thanks Ed, appreciate the clarification.

-Zack Barresse

> zackb <zackb@portofmorrow.com> was very recently heard to utter:
>> Hello Paul,
[quoted text clipped - 7 lines]
>
> i.e. Set page02 = oApp.ActiveDocument.Pages.Add(1, 2)
Ed Bennett - 26 Apr 2005 21:29 GMT
zackb <zackb@portofmorrow.com> was very recently heard to utter:
> Yes, I forget that when I write shorthand vba..  uh, oops.  LOL!
>
> Thanks Ed, appreciate the clarification.

No problem :-)

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.