But now I am getting a run-time error:
Run-time error:91 Object Variable or With Block Variable not set
When I click on debug, it takes me to the following line in code:
Set pFeat = pFCursor.NextFeature
Thanks again.
That's probably because you are not setting pFCursor anywhere (I don't think I provided that in my original post. sorry I am picking snippets from my own implementation which is different). See if this helps/completes the code. Sub CreateCentroid()
Dim pDoc As IMxDocument
Dim pMap As IMap
Set pDoc = Application.Document
Set pMap = pDoc.FocusMap
Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
Set pFSelection = pMap.Layer(0)
pSelectionSet = pFSelection.SelectionSet
''set the pfeaturecursor
pFCursor = Nothing
''Get a cursor from the selected features
pSelectionSet.Search(Nothing, False, pFCursor)
Dim pPoly As IPolygon
Dim pArea As IArea
Dim pPoint As IPoint
Dim lat As Long
Dim lon As Long
Dim pFeat As IFeature
Set pFeat = pFCursor.NextFeature
Do Until pFeat Is Nothing
Set pPoly = pFeat.ShapeCopy
Set pArea = pPoly
Set pPoint = pArea.Centroid
lat = pPoint.X
lon = pPoint.Y
Set pFeat = pFCursor.NextFeature
Loop
End Sub