Check if Master Exists: is there a more efficient way?

Started by daihashi, January 10, 2015, 01:45:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

daihashi

Yep... that works.

It's slow on the initial run, but it gets faster and faster as I run other routines due to more and more shapes being loaded into the document stencil.

With no stencils in the local document it takes about 1.1 seconds to run, then each subsequent run is about 0.2972 milliseconds. I think this is probably the best I will get it; I can certainly live with this performance anyway.

ignore the calls to obtimer; that is just the class module that I use as a performance timer.

Sub check_for_local_masters(ByRef mst_names() As String)
Dim i As Long
Dim mst As Visio.Master
Dim temp_s As String
Dim obTimer As New CHighResTimer
Dim shpID As Integer

obTimer.StartTimer
For i = LBound(mst_names) To UBound(mst_names)
    On Error Resume Next
    shpID = ActiveDocument.Masters(mst_names(i)).ID
    If Err.Number = 0 Then
        GoTo next_DOCmstr
    Else
        Err.Clear
        Application.ActiveWindow.Page.Drop Application.Documents.Item(ThisDocument.Path + ThisDocument.name).Masters.ItemU(mst_names(i)), 0, 0
        temp_s = gID
        Application.ActiveWindow.Page.Shapes.ItemFromID(temp_s).Cells("LockDelete").FormulaForceU = 0
        Application.ActiveWindow.Page.Shapes.ItemFromID(temp_s).Delete
    End If

next_DOCmstr:
Next i
obTimer.StopTimer
MsgBox "Check_for_local_masters took " & obTimer.Elapsed & " seconds"
End Sub