I have a VB.net application to produce a Visio drawing dynamiclly using values from a database. The issue is that when an instance of Visio is made I recieve this error.
System.InvalidCastException: QueryInterface for interface Microsoft.Office.Interop.IVApplication failed.
Code:
Sub fBuildFlowchart()
Dim vApp As Application
Dim vDoc As Document
Dim vFromShape As Shape
Dim vToShape As Shape
Dim vConnector As Shape
Dim vFlowChartMaster As Master
Dim vConnectorMaster As Master
Dim vStencil As Document
Dim dblXLocation As Double
Dim dblYLocation As Double
Dim vBeginCell As Cell
Dim vEndCell As Cell
Dim iCount As Integer
Const TEMPLATEPATH = "C:\Program Files\Visio\Solutions\Flowchart\Basic Flowchart Shapes.vss"
' Change this constant to match your choice of location and file name.
Const SAVENEWFILE = "C:\Simpleflowchart.vsd"
' Start point measured from the bottom left corner.
Try
dblXLocation = 4.25
dblYLocation = 8.5
vApp = New Application
'Create a new document; note the empty string.
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
vDoc = vApp.Documents.Add("")
FAILS HERE
vStencil = vApp.Documents.OpenEx(TEMPLATEPATH, 4)
Catch ex As Exception
MsgBox(ex.ToString)
End Try