I also use the IApprot interface.Added showing the Map title being attached to Dim m_appROT As ESRI.ArcGIS.Framework.IAppROT
m_appROT = New ESRI.ArcGIS.Framework.AppROT
Dim q As Object
'Cycle through appROT to work on the latest ArcMap open
If m_appROT.Count > 0 Then
For q = 0 To m_appROT.Count - 1
'If TypeOf m_appROT.Item(i) Is IGxApplication Then ' ArcCatalog running
If TypeOf m_appROT.Item(q) Is IMxApplication Then ' ArcMap running
If m_appROT.Item(q).Visible = True Then
If m_appROT.Item(q).Document.Title = lblConnectedTo.Text Then
pApp = m_appROT.Item(q) ' The session originally used.
End If
End If
End If
Next q
End If
Now you can go from there...Also added a public for several forms pObjectFactory = CType(pApp, IObjectFactory)
pApp = pObjectFactory
pDoc = pApp.Document
pApp = pDoc.Parent
pMxDoc = CType(pDoc, IMxDocument)
pMap = CType(pMxDoc.FocusMap, IMap) ' Focus on the map
Me.ArcGISApplication = pApp ' pass this to the public
A little extra, getting carried away, but now you can just use m_application in any SUB or Function Public WriteOnly Property ArcGISApplication() As ESRI.ArcGIS.Framework.IApplication
Set(ByVal value As ESRI.ArcGIS.Framework.IApplication)
m_application = value
End Set
End Property