Invalid Document ID

Started by Aranel, June 24, 2015, 06:34:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Aranel

So, I'm VERY new to VBA macros in Visio. I copied and pasted this code from MSDN: Option Explicit
Sub connectdata()
    Call AddDataRecordset
   
    Call LinkDataToNewShapes
    Call DisplayExternalDataWindow
    Call ApplyDataGraphic
   
End Sub
Public Sub AddDataRecordset()
    Dim strConnection As String
    Dim strCommand As String
    Dim vsoDataRecordset As Visio.DataRecordset
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _
                       & "User ID=Admin;" _
                       & "Data Source=C:\Users\duehrs\Documents\Sales Data.xlsx;" _
                       & "Mode=Read;" _
                       & "Extended Properties=""HDR=YES;IMEX=1;MaxScanRows=0;Excel 12.0;"";" _
                       & "Jet OLEDB:Engine Type=35;"
    strCommand = "Select * from [Sales by Region$]"
    Set vsoDataRecordset = ActiveDocument.DataRecordsets.Add(strConnection, strCommand, 0, "Regional Sales Data")
End Sub

Public Sub DisplayExternalDataWindow()
    Application.ActiveWindow.Windows.ItemFromID(visWinIDExternalData).Visible = True
End Sub


Public Sub LinkDataToNewShapes()

    Dim avarObjects(0 To 3) As Variant
    Dim adblXYs(0 To 7) As Double
    Dim alngDataRowIDs(0 To 3) As Long
    Dim alngShapeIDs() As Long
    Dim vsoDataRecordset As Visio.DataRecordset
    Dim intRecordsetCount As Integer
    Dim lngReturned As Long
    Dim intCounter As Integer
    Dim intObjectNumber As Integer
   
    intRecordsetCount = Visio.ActiveDocument.DataRecordsets.Count
    Set vsoDataRecordset = Visio.ActiveDocument.DataRecordsets(intRecordsetCount)
   
   
   
    For intObjectNumber = 0 To 3
   
        Set avarObjects(intObjectNumber) = Visio.Documents("Basic_U.VSS").Masters("Rectangle")<---***
   
    Next
   
    adblXYs(0) = 4
    adblXYs(1) = 8
    adblXYs(2) = 4
    adblXYs(3) = 6
    adblXYs(4) = 4
    adblXYs(5) = 4
    adblXYs(6) = 4
    adblXYs(7) = 2
       
    alngDataRowIDs(0) = 1
    alngDataRowIDs(1) = 2
    alngDataRowIDs(2) = 3
    alngDataRowIDs(3) = 4
       
    lngReturned = ActivePage.DropManyLinkedU(avarObjects, adblXYs, vsoDataRecordset.ID, alngDataRowIDs, False, alngShapeIDs)
    Debug.Print lngReturned
   
    For intCounter = 0 To lngReturned - 1
        Debug.Print alngShapeIDs(intCounter)
    Next
   
End Sub


Public Sub ApplyDataGraphic()
    Dim vsoSelection As Visio.Selection
    ActiveWindow.SelectAll
    Set vsoSelection = ActiveWindow.Selection
    vsoSelection.DataGraphic = ActiveDocument.Masters("Sales Data")
End Sub

'Public Sub InsertTitleAndShapeText()

  '  Dim vsoShape As Visio.Shape
   ' Dim vsoCharacters As Visio.Characters
   
   ' Set vsoShape = ActivePage.Drop(Application.Documents.Item("BORDER_U.VSS").Masters.ItemU("Title block classic"), 4.25, 9.875)
   ' Set vsoCharacters = ActivePage.Shapes.ItemFromID(vsoShape.ID + 1).Characters
   ' vsoCharacters.Begin = 0
   ' vsoCharacters.End = 27
   ' vsoCharacters.Text = "Quarterly Sales by Region"

'End Sub


It keeps saying I have an invalid document identifier at the line with <---***

What am I doing wrong?!

Thanks!

Surrogate

it is whole code or only part ?

Are you sure that problem with invalid documents ID ?
Visio.Documents("Basic_U.VSS").Masters("Rectangle")  is not documents ID !

Dim D As Variant
D = Visio.Documents("Basic_U.VSS").Masters("Rectangle")
Debug.Print TypeName(D) ' string
Debug.Print TypeName(Visio.Documents("Basic_U.VSS").Masters("Rectangle")) ' master



Aranel

#2
I think that's all the code. I got it from here: https://msdn.microsoft.com/en-us/library/bb743267(v=office.12).aspx.

After it crashes and I click "Debug" in the dialog box that appears, the line with <---*** is highlighted and when I hover over "Visio.Documents("Basic_U.VSS").Masters("Rectangle")" it says "Invalid document identity."

Thanks for the help!

Paul Herber

Ah, which version of Visio are you using?
The file "Basic_U.vss" doesn't exist in standard Visio now (it was in all versions up to and including Visio 2010). Visio 2013 onwards it is a new format and new extension type. "basic_U.vssx" I think.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Aranel

I'm using Visio 2007. I thin I'm going to try using a different .vss file.

That's a stencil, right?

Surrogate

which of Visio 2007 version: Standart or Professional ?

Paul Herber

I think the code is expecting the basic and border stencils to be already open.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/