visio Automation

Add-in Express™ Support Service
That's what is more important than anything else

visio Automation
Update data in shapes 
Alexander Feduleev




Posts: 4
Joined: 2011-12-09
Hi,

I need update shapes from recordset in Visio 2007.

Record macro in Visio and get code like this :

Application.ActiveWindow.SelectAll
Dim ColumnNames2(1) As String
Dim FieldTypes2(1) As Long
Dim FieldNames2(1) As String
Dim IDsofLinkedShapes2() As Long
ColumnNames2(0) = "Person Number"
FieldTypes2(0) = 3 ' visAutoLinkUserRowName
FieldNames2(0) = "PersonNumber"
Application.ActiveWindow.Selection.AutomaticLink 3, ColumnNames2, FieldTypes2, FieldNames2, 8, IDsofLinkedShapes2 'visAutoLinkReplaceExistingLinks

Problem is when I make the same code in VB.NET

Dim visSelection As Visio.Selection
Dim ColumnNames1(0) As String
Dim FieldTypes1(0) As Long
Dim FieldNames1(0) As String
Dim linkedShapeIDs As System.Array = Array.CreateInstance(GetType(Long), 0)


Try

VisioApp.Application.ActiveWindow.SelectAll()
visSelection = VisioApp.Application.ActiveWindow.Selection
ColumnNames1(0) = "Person Number"
FieldTypes1(0) = 3 'visAutoLinkUserRowName
FieldNames1(0) = "PersonNumber"
visSelection.AutomaticLink(3, ColumnNames1, FieldTypes1, FieldNames1, 8, linkedShapeIDs) 'visAutoLinkReplaceExistingLinks
Catch ex As Exception
MsgBox("Error link data to shapes " + vbCrLf + ex.Message.ToString, MsgBoxStyle.Critical)
End Try


I get an error

Exception in HRESULTS 0x80020005 DISP_E_TYPEMISMATCH

I'm tested with different variants, but the same error.
Error starts when I'm apply 3rd parameter to AutomaticLink.

Can you help me ?
How correct define variables to call this Visio selection method ?

Best Regards,
Alexander Feduleev
Posted 16 Dec, 2011 07:05:57 Top
Andrei Smolin


Add-in Express team


Posts: 16681
Joined: 2006-05-11
Hi Alexander,

Try using "Dim FieldTypes1(0) As Integer".

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Dec, 2011 07:46:27 Top
Alexander Feduleev




Posts: 4
Joined: 2011-12-09
Hi Andrei,

I'm tried, the same error :(

Alex
Posted 17 Dec, 2011 00:20:33 Top
Andrei Smolin


Add-in Express team


Posts: 16681
Joined: 2006-05-11
Hi Alexander,

Try also using "Dim linkedShapeIDs As System.Array = Array.CreateInstance(GetType(Integer), 0)".

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 19 Dec, 2011 00:30:00 Top