Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB.NET
I have in past an application that generate the Organizational Chart of a company, on Visio 2007 But now when i have installed Visio 2013/2016 the code didn't work and throw the below exception :

Inappropriate target object for this action.


What I have tried:

the exception was thrown when i want to change the text of a shape, Below are my code:

Dim vApp As Microsoft.Office.Interop.Visio.Application
Dim vDoc As Microsoft.Office.Interop.Visio.Document
Dim vFromShape As Microsoft.Office.Interop.Visio.Shape
Dim vToShape As Microsoft.Office.Interop.Visio.Shape

Dim vFlowChartMaster As Microsoft.Office.Interop.Visio.Master

Dim vStencil As Microsoft.Office.Interop.Visio.Document
Dim dblXLocation As Double
Dim dblYLocation As Double

Dim TEMPLATEPATH = genInfo.templatesDirectory & "ORGCH_M.VSS"


Dim vApp As Microsoft.Office.Interop.Visio.Application
Dim vDoc As Microsoft.Office.Interop.Visio.Document
Dim vFromShape As Microsoft.Office.Interop.Visio.Shape
Dim vToShape As Microsoft.Office.Interop.Visio.Shape

Dim vFlowChartMaster As Microsoft.Office.Interop.Visio.Master

Dim vStencil As Microsoft.Office.Interop.Visio.Document
Dim dblXLocation As Double
Dim dblYLocation As Double

Dim TEMPLATEPATH = genInfo.templatesDirectory & "ORGCH_M.VSS"

Dim tblOC As DataTable = GetOrganizationalChartReport(Entity, AccEntity, Division, Department, Unit)


If tblOC IsNot Nothing AndAlso tblOC.Rows.Count > 0 Then
vFlowChartMaster = vStencil.Masters(tblOC.Rows(0)!shape)
vToShape = vApp.ActivePage.Drop(vFlowChartMaster, dblXLocation, dblYLocation)
vToShape.Text = String.Format("{0} {1}{2}{3}{4}", tblOC.Rows(0)!fullname, Environment.NewLine, tblOC.Rows(0)!Department, _
Environment.NewLine, tblOC.Rows(0)!jobtitle)

Dim UndoScopeID1, UndoScopeID2 As Long
UndoScopeID1 = vApp.BeginUndoScope("Size Object")
UndoScopeID2 = vApp.BeginUndoScope("Size Object")

vApp.ActiveWindow.Page.Shapes.ItemFromID(vToShape.ID).CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaForceU = "15 mm"
vApp.EndUndoScope(UndoScopeID1, True)

vApp.ActiveWindow.Page.Shapes.ItemFromID(vToShape.ID).CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = "30 mm"
vApp.EndUndoScope(UndoScopeID2, True)

Reportsto = tblOC.Rows(0)!Unique_ID
functionalSup = tblOC.Rows(0)!functionalSup

vFromShape = vToShape

Dim MSVisioShapeObj As New MSVisioShape(vFromShape.ID, vToShape.ID, tblOC.Rows(0)!Unique_ID, tblOC.Rows(0)!Reports_to, tblOC.Rows(0)!FunctionalSup)
functionalShapeslst.Add(MSVisioShapeObj)

vToShape = Nothing
Call AddSubOrdinates(Reportsto, functionalSup, vApp, vFromShape, vStencil, dblXLocation, dblYLocation, vDoc, functionalShapeslst, Entity, AccEntity)
End If

The exception is thrown in the below line of code:

vToShape.Text = String.Format("{0} {1}{2}{3}{4}", tblOC.Rows(0)!fullname, Environment.NewLine, tblOC.Rows(0)!Department, Environment.NewLine, tblOC.Rows(0)!jobtitle)

is there anything changed in the newly version of Visio ?
Posted
Comments
Sergey Alexandrovich Kryukov 15-Apr-16 9:19am    
I would never use Visio; it could be easier to create some diagramming system from scratch, especially with WPF. I found Visio to be amazingly bad product acquired by Microsoft. What could it possibly offer except all those boxes and lines which you can draw by yourself exactly as you want?

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900