[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 499
  • Last Modified:

Visio VBA - Macro not running Undeciperable error message

I received the following error message when I attempted to run a macro.
The macro was attached to a rectangle which had a double-click behavior set to RUN MACRO.err
0
brothertruffle880
Asked:
brothertruffle880
  • 3
3 Solutions
 
Robberbaron (robr)Commented:
you need to tell us more about what the actual macro is doing when the error throws....

i seem to recall having the -2147467259 error before (in AutoCad) and it was to do with OLE or automation (Autocad not ready...)

http://social.msdn.microsoft.com/Forums/en-US/33096079-bb3c-4acc-9ba1-dc1972af3cd9/excel-automation-bug-error-214746725980004005?forum=exceldev
0
 
Dennis AriesCEO @ Arkro ITCommented:
There are a number of causes possible for this error. Is it possible to upload the macro that you are tryin to run?
0
 
Robberbaron (robr)Commented:
http://support.microsoft.com/kb/286126 has some possible workarounds
0
 
brothertruffle880Author Commented:
It's a macro that switches layers in a Visio file.  Here's one particular calling proc:
Dim pg As Visio.Page
  Set pg = Visio.ActivePage
  Call m_showAndHideLayers(pg, LayerName_Mgmt$)
  Set pg = Nothing

Open in new window


Here is the rest of the module:
'// ----- Private Procedures --------------------------------------------------
Private Sub m_showAndHideLayers(ByRef visPg As Visio.Page, _
                                ByVal sLayerNameToShow As String)
  
        If (visPg.Layers.Count = 0) Then
          Call MsgBox("The active page has no layers!" & vbCrLf & vbCrLf & _
                  "No changes to layers will be made.")
          GoTo Cleanup
        End If
        
  '// Try and get the target layer:
  Dim lyrTarget As Visio.Layer, lyr As Visio.Layer
  Set lyrTarget = m_getLayerByName(visPg, sLayerNameToShow)
    
        If (lyrTarget Is Nothing) Then
            '// Layer not found, so don't do anything at all
            Call MsgBox("Layer: '" & sLayerNameToShow & "' was not found!" & vbCrLf & vbCrLf & _
                        "No changes to layers will be made.")
            GoTo Cleanup
          Else
            '// The layer was found, turn it visible and active:
            lyrTarget.CellsC(Visio.VisCellIndices.visLayerVisible).ResultIU = 1
            lyrTarget.CellsC(Visio.VisCellIndices.visLayerActive).ResultIU = 1
            
            '// Turn all the other layers invisible and inactive:
            Dim i As Integer
            For i = 1 To visPg.Layers.Count
            
              Set lyr = visPg.Layers.Item(i)
                    If (Not (lyr Is lyrTarget)) Then
                      lyr.CellsC(Visio.VisCellIndices.visLayerVisible).ResultIU = 0
                      lyr.CellsC(Visio.VisCellIndices.visLayerActive).ResultIU = 0
                    End If
            Next i
          End If
 
Cleanup:
  '// Cleanup:
  Set lyrTarget = Nothing
  Set lyr = Nothing

End Sub

Private Function m_getLayerByName(ByRef pg As Visio.Page, _
                                  ByVal sLayerName As String) As Visio.Layer

  Set m_getLayerByName = Nothing
  
  Dim lyr As Visio.Layer
  For Each lyr In pg.Layers
    If (StrComp(sLayerName, lyr, vbTextCompare) = 0) Then
      Set m_getLayerByName = lyr
      Exit For
    End If
  Next lyr
  
  '// Cleanup:
  Set lyr = Nothing
  
End Function

Open in new window

0
 
Robberbaron (robr)Commented:
on what line in the macro does it throw error ?
is it  Set pg = Visio.ActivePage  ?

try wrapping each call in the main routine in a check loop like

on error resume next
errcount=0
do
    Set pg = Visio.ActivePage
    errCount = errCount + 1
loop while err.number = -2147467259 and errCount < 5
if errCount = 5 then  MsgBox "error getting Activepage"

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now