Public Sub Test() ' Get layer Dim pMXDocument As IMxDocument Set pMXDocument = ThisDocument Dim pMap As IMap Set pMap = pMXDocument.FocusMap Dim pLayer As ILayer Set pLayer = pMap.Layer(0) Dim pFeatureLayer As IFeatureLayer Set pFeatureLayer = pLayer ' Get the 40,000 selected polygons Dim pFeatureSelection As IFeatureSelection Set pFeatureSelection = pFeatureLayer Dim pSelectionSet As ISelectionSet Set pSelectionSet = pFeatureSelection.SelectionSet Debug.Print pSelectionSet.Count ' Create cursor over selection Dim pCursor As ICursor pSelectionSet.Search Nothing, False, pCursor Dim pRow As IRow Set pRow = pCursor.NextRow Dim pPolygon As IPolygon Dim pGeometryBag As IGeometryBag Set pGeometryBag = New GeometryBag Dim pSpatialReference As ISpatialReference Dim pGeoDataset As IGeoDataset Set pGeoDataset = pFeatureLayer.FeatureClass Set pSpatialReference = pGeoDataset.SpatialReference Set pGeometryBag.SpatialReference = pSpatialReference Dim pGeometryCollection As IGeometryCollection Set pGeometryCollection = pGeometryBag ' Add polygons to bag Debug.Print "Adding to geometry bag" Do While Not pRow Is Nothing Set pPolygon = pRow.Value(pRow.Fields.FindField("Shape")) pGeometryCollection.AddGeometry pPolygon Set pRow = pCursor.NextRow Loop Debug.Print "done looping" ' Do the union Dim pTopoOp As ITopologicalOperator Set pTopoOp = New Polygon Dim pEnumGeometry As IEnumGeometry Set pEnumGeometry = pGeometryBag Debug.Print CStr(pEnumGeometry.Count) & " in bag" pEnumGeometry.Reset pTopoOp.ConstructUnion pEnumGeometry Debug.Print "Got here with out error!" End Sub