VBA Runtime Error 438.

Started by Michael, January 14, 2011, 02:58:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Michael

"Object Doesn't support this property or method."

Am trying to pick off the existing addresses & subaddresses from all the shapes on a page and get the above error running the following code:

+++

Public Sub filename()
   
    Dim pg As Visio.Page
    Dim shp As Visio.Shape
    Dim myText As String
    Dim filename As String
    Dim filetype As String
    Dim subadd As String
    Dim shpid As String
    Dim exadd As Visio.Hyperlink
    Dim exsubadd As Visio.Hyperlink
   
    If MsgBox("Do you really want to print all the shape data?", vbYesNo) = vbNo Then Exit Sub
     
    For Each pg In ActiveDocument.Pages
    Debug.Print "Page Name: " + pg.Name
        For Each shp In pg.Shapes
       
            myText = ""
            filename = ""
            filetype = ""
            subadd = ""
            shpid = ""
            'exadd = ""
            'exsubadd = ""
           
        If shp.Characters.Text <> "" Then
               'myText = shp.Characters.Text
               If Left(shp.Name, 22) = "Predefined KWF Process" Then
                  filetype = "vsd"
                  'Filename can be Tree00.vsd - Tree15.vsd. Derive it from the digits to the left of the first space in the shape text
                  filename = Left("Tree00", 6 - Len(Trim(Left(shp.Characters.Text, 2)))) + Trim(Left(shp.Characters.Text, 2)) + "." + filetype
                  subadd = shp.Text
               ElseIf Left(shp.Name, 8) = "Document" Then
                  filetype = "doc"
                  filename = shp.Text + "." + filetype
               Else
                  filetype = "txt"
                  filename = shp.Text + "." + filetype
               End If
               'shp.Text = "xxx"
               'shp.Text = myText
               Debug.Print "  Shape ID: " + shp.NameID
               Debug.Print "  Shape Text: " + shp.Text
               Debug.Print "  Shape Type: " + shp.Name
               Debug.Print "  Ex Add: " + shp.Address
               Debug.Print "  Ex Sub Add: " + shp.SubAddress
               Debug.Print "  File Name: " + filename
               Debug.Print "  Sub-Address: " + subadd
               Debug.Print " "
        End If
        Next
    Next

End Sub

+++

It fails at "Debug.Print "  Ex Add: " + shp.Address.

Is there a way around this? The help file seems to indicate it's version/release specific. SDK states it was available from version 5; I'm running Visual Basic 6.5 according to the "About..." dialogue. Visio release is 2003 SP3.

aledlund

Since Address and SubAddress are cells within the Hyperlinks section, I suspect that the shape you tested did not have a hyperlinks section. You should probably test to see if the section exists before testing the cell contents.
al

ps Chris likes us to wrap our code in code tags

http://visguy.com/vgforum/index.php?topic=89.0

Michael

OK.

Not sure what the problem was as basically I'm running on multiple copies of the same diagram (only the shape text is different (at the moment), so it should have worked.

Anyhow, I bit the bullet and went straight to creating addresses & subAddresses from the shape.text, page names & file names (and then creating a whole raft of .txt files with the same names for the hyperlinks to point to - and that seemed to have worked (at least on one of my 15 files).

It's all a bit "proof of concept" for me at the moment with excellent hints & pointers coming from various threads on here (so thanks, again, to everyone).

I need to go back over all my code and tidy it up once I'm happy with it, and if it's of any interest to anybody, I'm more than happy to put it up on the site for comment.

Thanks also for the heads-up on the code tags - they do make things easier to read. I'll try to remember for the future :-)