Solved

Visio VBA - Macro not running Undeciperable error message

Posted on 2014-01-21
5
457 Views
Last Modified: 2014-01-22
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
Comment
Question by:brothertruffle880
  • 3
5 Comments
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 500 total points
ID: 39799295
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
 
LVL 18

Expert Comment

by:Dennis Aries
ID: 39799298
There are a number of causes possible for this error. Is it possible to upload the macro that you are tryin to run?
0
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 500 total points
ID: 39799301
http://support.microsoft.com/kb/286126 has some possible workarounds
0
 

Author Comment

by:brothertruffle880
ID: 39799413
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
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 39799522
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A recent Visio zone question asked how to use the data in an Excel file to create a Visio Gantt chart -- and then to dynamically update the Gantt chart. The good news is that the Viso Gantt Chart wizard can be automated. The bad news is that the…
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article we’ll examine containers. We’ll explore lists (http://www.experts-exchange.com/Microsoft/Applications/M…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now