What I mean is: We have three macros. Sitting at my station, with two dwgs open, two of the macros work fine in both dwgs. One of the macros works fine in an older dwg, but returns "Execution Error" in the other dwg. The macro is supposed to count the number of block instances, populate a schedule and prompt the user for an insertion point.
Sub PanelSchedule()
' This routine inserts a panel schedule into a 1/4-scale drawing file
' This routine counts the panels in a drawing
Dim ss1 As AcadSelectionSet
Set ss1 = ssAdd("ssName")
Dim codes(0) As Integer
Dim values(0)
Dim straightCount As Integer
Dim leftCount As Integer
Dim rightCount As Integer
Dim doubleCount As Integer
Dim hdrCount As Integer
Dim hdlCount As Integer
codes(0) = 2 '2 is filter number for blocknames
'Initialize counts to zero
straightCount = 0: leftCount = 0: rightCount = 0: doubleCount = 0: hdrCount = 0: hdlCount = 0
'Straights
ss1.Clear
values(0) = "Straight"
ss1.Select acSelectionSetAll, , , codes, values
straightCount = ss1.Count
ss1.Clear
values(0) = "Straight Through Panel"
ss1.Select acSelectionSetAll, , , codes, values
straightCount = straightCount + ss1.Count
'Lefts
ss1.Clear
values(0) = "Left"
ss1.Select acSelectionSetAll, , , codes, values
leftCount = ss1.Count
ss1.Clear
values(0) = "Left Turn Panel"
ss1.Select acSelectionSetAll, , , codes, values
leftCount = leftCount + ss1.Count
'Rights
ss1.Clear
values(0) = "Right"
ss1.Select acSelectionSetAll, , , codes, values
rightCount = ss1.Count
ss1.Clear
values(0) = "Right Turn Panel"
ss1.Select acSelectionSetAll, , , codes, values
rightCount = rightCount + ss1.Count
'Full Doubles
ss1.Clear
values(0) = "Double"
ss1.Select acSelectionSetAll, , , codes, values
doubleCount = ss1.Count
ss1.Clear
values(0) = "Double Turn Panel"
ss1.Select acSelectionSetAll, , , codes, values
doubleCount = doubleCount + ss1.Count
'HD Lefts
ss1.Clear
values(0) = "Half Double - Left Turn"
ss1.Select acSelectionSetAll, , , codes, values
hdlCount = ss1.Count
ss1.Clear
values(0) = "HD-L"
ss1.Select acSelectionSetAll, , , codes, values
hdlCount = hdlCount + ss1.Count
'HD Rights
ss1.Clear
values(0) = "Half Double - Right Panel"
ss1.Select acSelectionSetAll, , , codes, values
hdrCount = ss1.Count
ss1.Clear
values(0) = "HD-R"
ss1.Select acSelectionSetAll, , , codes, values
hdrCount = hdrCount + ss1.Count
doubleCount = doubleCount + (IIf((hdlCount > hdrCount), hdlCount, hdrCount))
' Insert the block
Dim pSchedule As AcadBlockReference
Set pSchedule = ThisDrawing.ModelSpace.InsertBlock(ThisDrawing.Utility.GetPoint(, "Insertion point: "), "PanelCntBlk.dwg", 1#, 1#, 1#, 0)
' Get the attributes for the block reference
Dim varAttributes As Variant
varAttributes = pSchedule.GetAttributes
varAttributes(0).TextString = straightCount
varAttributes(1).TextString = leftCount
varAttributes(2).TextString = rightCount
varAttributes(3).TextString = doubleCount
' Move the attribute tags and values into a string to be displayed in a Msgbox
' Dim strAttributes As String
' Dim I As Integer
' For I = LBound(varAttributes) To UBound(varAttributes)
' strAttributes = strAttributes & " Tag: " & varAttributes(I).TagString & _
' " Value: " & varAttributes(I).TextString & " "
' Next
' MsgBox "The attributes for " & pSchedule.Name & " are: " & strAttributes, , "GetAttributes Example"
End Sub
Public Function ssAdd(strName As String) _
As AcadSelectionSet
On Error Resume Next
ThisDrawing.SelectionSets(strName).Delete
Set ssAdd = ThisDrawing.SelectionSets.Add(strName)
End Function