VBA button in normal.mxt vs project.mxd

657
8
09-24-2010 05:44 AM
Highlighted
by Anonymous User
Not applicable
Original User: alnesbit

Hi all,

I wanted to put code in the normal.mxt instead of the mxd but it doesn't work. The code just launches a toolbar that I created. Why doesn't this work in the normal.mxt?

Private Sub UIButtonControl9_Click()

    Dim pCmdBars As ICommandBars
    Set pCmdBars = ThisDocument.CommandBars
    Dim pCmdBar As ICommandBar
    Set pCmdBar = pCmdBars.Find("Project.Parcel Split")
    If Not pCmdBar.IsVisible Then
        pCmdBar.Dock esriDockToggle
    Else
        pCmdBar.Dock esriDockToggle
    End If

End Sub

Thanks
Reply
0 Kudos
8 Replies
Highlighted
Regular Contributor
If you are using ArcGIS 10 then you can no longer save UI controls in the Normal Template. You can still do so in the document-Level.  In ArcCatolog UI controls are still available.
Reply
0 Kudos
Highlighted
by Anonymous User
Not applicable
Original User: alnesbit

Ok, I am using 9.3.1.

but good to know about 10. thanks.
Reply
0 Kudos
Highlighted
Regular Contributor
mxt is a template file for mxd documents. In VBA, when you place code in the "Normal (Normal.mxt)" Project (see attached) you are actually placing the code in the "Normal.mxt" template from which all documents will "inherit" this custom behavior. This goes for both 9.3 and version 10. With the exception that older versions (8 - 9.x.x) you can also add custom buttons and other controls into your global normal template (Normal.mxt) but in version 10 you cannot.
Reply
0 Kudos
Highlighted
by Anonymous User
Not applicable
Original User: alnesbit

right, I'm with you.

My question still remains. This simple code won't run when I put the button and the code in the normal.mxt instead of the mxd. Does it run for anyone else on 9.3.1? Maybe it's something with a library. I'm not sure why it won't work.

Thanks,
Reply
0 Kudos
Highlighted
Regular Contributor
If the toolbar has been created in the Normal template try this:

Set pCmdBar = pCmdBars.Find("Normal.ThisDocument.Parcel Split")

instead of:

Set pCmdBar = pCmdBars.Find("Project.Parcel Split")
Reply
0 Kudos
Highlighted
by Anonymous User
Not applicable
Original User: alnesbit

ah, good point. I will give that a try.

Thanks!
Reply
0 Kudos
Highlighted
by Anonymous User
Not applicable
Original User: alnesbit

Hello,

Well, that didn't work either. I get Run time error 91, Object variable or With block variable not set.

It debugs to the line after the '*.

Private Sub LaunchPToolbar_Click()

Dim pCmdBars As ICommandBars
Set pCmdBars = ThisDocument.CommandBars
Dim pCmdBar As ICommandBar
Set pCmdBar = pCmdBars.Find("Normal.ThisDocument.ParcelSplit")
'*
If Not pCmdBar.IsVisible Then
pCmdBar.Dock esriDockToggle
Else
pCmdBar.Dock esriDockToggle
End If

End Sub

Any other thoughts or ideas? (Yes my toolbar is in the normal and it is called "ParcelSplit")

Thanks in advance,
Reply
0 Kudos
Highlighted
New Contributor III
I was able to save UI controls in the Normal Template by replacing the normal.mxt with a 9.3.1 normal.mxt.
Reply
0 Kudos