if I need to work with classes MxDocument with the MapDocument that I have selected to work , for example style gallery, How can I instantiate ?


pMapDoc = CreateObject(esriCarto.MapDocument, interface = esriCarto.IMapDocument)

pApp = GetApp()
pMxDoc = CType(pApp.Document, esriArcMapUI.IMxDocument)
pSG = CType(pMxDoc.StyleGallery, esriDisplay.IStyleGallery)

Can I relate this?

1 Answer 1


According to my opinion you are mixing something up. If you are writing some code to use inside a running ArcMap process you have to work with the IMxDocument. In a standalone application without ArcMap only using arcobjects you have to work with the IMapDocument to access an MXD. Using both at once does not work correctly.

If you like to access the style gallery with IMxDocument you can use its member IMxDocument.StyleGallery, which is loaded and instantiated by the ArcMap application automatically.

If you are working with an IMapDocument there is no such member because there is no style manager window loaded. If the StyleGallery is ever usable in combination with the IMapDocument, I would try to create it this way. But it is not tested.

pSG = CreateObject(Display.StyleGallery, interface = Display.IStyleGallery)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.