Adding Pages Progmatically in Visio 2003

  • Thread starter Larry - tekWorx, LLC.
  • Start date
L

Larry - tekWorx, LLC.

I have an application that I developed in VB.Net that accesses visio from the
program and creates drawings.

I originally programmed the application to work with Visio 2002 and never
had any problems.

I just upgraded to Visio 2003 and now the program gives me an error when it
tries to create my drawing file...

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in Project Developer.exe

Additional information:

Requested operation is presently disabled.

The program stops at the following line:

newPage = curDoc.Pages.Add

It seems that I can no longer add a page. I checked to make sure that the
Markup is OFF, but it will still not allow me to add pages.

Any help is greatly appreciated!
 
L

Larry - tekWorx, LLC.

Yep... curDoc is a valid object. In fact, if I don't do a page.add command,
but set a reference to the first page, my program will start adding shapes.
This won't work as a solution because my program will generate drawings that
are sometimes 20+ pages

Once the program starts adding shapes it works fine, until I attempt to
rotate a shape using the Rotate90 function. I then get the exact same error
and the program stops functioning at the newShape.Rotate90 line.

Error is still:

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in Project Developer.exe

Additional information:

Requested operation is presently disabled.
 
L

Larry - tekWorx, LLC.

Here's some setup information:

I have a subroutine that looks like this:

Public Sub Create_Drawing()
Dim FileName As String
Dim App As Microsoft.Office.Interop.Visio.Application, newDoc As
Microsoft.Office.Interop.Visio.Document, Stencil As
Microsoft.Office.Interop.Visio.Document
Dim curPage As Microsoft.Office.Interop.Visio.Page

App = New Microsoft.Office.Interop.Visio.Application

FileName = Project.TemplatePath + "Template.vst"
newDoc = App.Documents.Add(FileName)

FileName = Project.StencilPath + "Parts.vss"
Stencil = App.Documents.Add(FileName)

curPage = InsertPowerPage(newDoc, Stencil)
End If
End Sub

Now, if I add a page in this subroutine, just below the newDoc =
App.Documents.Add(FileName) line

curPage = newDoc.Pages.Add

Then a new page will be added and no error is generated. However, when the
program gets to the sub InsertPowerPage and attempts to add a page in this
sub, that's when the error is generated.

I am passing my arguments (newDoc and Stencil) ByRef, and this works
perfectly when using Visio 2002.

Any Thoughts??
 
A

Al Edlund

Larry,
as general observation when I am doing code (granted I'm pretty intense on
recovery) I use a lot of try... catch...endtry flows to catch errors. What
are the chances that the com exception is in the called routine and it is
not transferring back the correct object (thus the com exception in the
caller). Since you haven't shared the prototype of the called routine I'm
kinda guessing in the wind.
Al
 
L

Larry - tekWorx, LLC.

OK... this is bizarre.

I wrote a stub program to test what's going on... what I found out was that
if I added my "Page.Add" call BEFORE adding in my stencil that it works OK,
but after the call to add my stencil, it doesn't.

SO... I reversed the order and added my stencil to the document BEFORE my
template and in the stub program it works fine.

SO... I went back to my full program and reversed the order of adding the
stencil first and the template second... it's now working without error.

Go Figure !?
 

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