Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deploy new menu item 2

Status
Not open for further replies.

joemajestee

Programmer
May 5, 2010
35
US
Hi all.
I have a word 2003 file menu item that I would like to be made available to all users in my network. Also, I would like to have new users get it when I am not there to set it up manually.

Any suggestions?

I have knowledge of login scripts and default file locations, if that helps. Also the default user profile is saved in netlogon so everyone gets the same one.

If it helps, here is the simple code. Not sure where to put it, right now it's in normal.dot in the thisdocument area. As it stands, the item is not there until I create a new document, although I would like it to be there always.

Code:
Private Sub Document_New()
On Error Resume Next
SetUpNewLeaseItemOnFileMenu
End Sub

Private Sub Document_Close()
On Error Resume Next
RemoveNewLeaseFromFileMenu
End Sub

Sub SetUpNewLeaseItemOnFileMenu()
Dim FileMenu As CommandBar, MenuItem As Object
Set FileMenu = CommandBars("File")
With FileMenu.Controls
    Set MenuItem = .Add(Type:=msoControlButton, Before:=2)
    With MenuItem
        .Caption = "New Lease"
        .OnAction = "NewLease"
    End With
End With
End Sub
 
As it stands, the item is not there until I create a new document,
This is as it should be, as you have the code in Document_New. New document, new menu item.
I would like it to be there always.
Then it must be either in normal.dot, or another global template that is loaded (usually on Startup).

The most important issue however is the procedure called by the menu item. This MUST be available if you are going to get it for all users.

The solution (or one anyway) is a global template, but NOT normal. Generally speaking it is a bad idea to push normal.dot onto users. Carefully done, it is viable, but generally it is not a good idea. Why? Because it is far too easy for the intended result to get corrupted/changed.

So. What you can do is make a wee global template with your menu item AND the procedure fired by it. You somehow need to get that into each users Startup. This is a local folder.

Here is the situatuion. Word accesses procedures (macros) from:

1. normal.dot (local)
2. other global templates (local OR network)
3. documents

Regrading #2, a global can be on a network drive, but something has to be local that points to it. In other words, you could have the gloabl with your menu item and procedure on a network dribe, but something has to be local that points to it.

So if you want this for all documents, then you have to place it in your normal, or a local global.

If you want this for all users, then you have to eithe rhave it in their normal.dot, or in a global that is available to them.
I have knowledge of login scripts
One possible solution then is to write the global to each users Startup upon login. Then, when they start Word, that global will be loaded.

Gerry
 
You got it working already. Boy that was fast.

In that case, here is another possible suggestion that may help with other situations.

Obviously if you wrote that wee global and scripted it into all users Startup, then that will be loaded upon Startup. That means that menu item will be on all documents.

Suppose you do not want that? You can load globals (including menu items) dynamically.

I have a .dot file with hundreds of procedures. However, I certainly do not need them all the time. True, the overhead is not huge, but in principle IMO best-practice is to have things when you need them, and not have them when you do not need them. So.
Code:
Sub LoadVBA_DOT()
Dim myAddin As AddIn
For Each myAddin In AddIns
   If myAddin.Name = "VBA XTools.dot" Then
      AddIns("U:\WordGlobals\VBA XTools.dot").Installed = False
      AddIns("U:\WordGlobals\VBA XTools.dot").Delete
      GoTo MyEnd:
   End If
Next
   AddIns.Add "U:\WordGlobals\VBA XTools.dot", Install:=True
MyEnd:
End Sub
The global LoadVBA.dot is scripted to Startup, but it only has one procedure.

Sub LoadVBA_Dot()

It also has an icon that is placed on the top toolbar. The icon fires LoadVBA_Dot. It acts as a toggle.

If the global VBA XTools.dot is not installed and loaded (there is a difference!), install and load it.

If the global VBA XTools.dot IS installed, remove all traces of it.

VBA XTools.dot sits on a network drive. It is about 600 K (lots of modules, userforms, menu items, icons yadda yadda).

LoadVBA.dot sits in Startup. It is 30K.

Now the reason I am mentioning this is that depending on requirements, you can have (or not have) whatever you want.

So, on each user local Startup, a wee global that puts a new menu item. Just one. I am making this up as an example.

"Load Macros"

Load Macros has sub-menu items.

Load Macros
Financial
Personnel
Marketing
Memos
Fax templates (anyone still using fax?)
Whatever Blah Blah

Are you following? ONE wee global loaded from Startup. It does ONE thing - give pointers to OTHER globals that are on the network.

User clicks "Financial" which fires:
Code:
    AddIns.Add "U:\WordGlobals\Financial", Install:=True
                 OR if you want to toggle
    AddIns("U:\WordGlobals\Financial.dot").Installed = False
    AddIns("U:\WordGlobals\Financial.dot").Delete
          etc. etc.
This loads the financial global with all its procedures, menu items, userforms.....whatever.

User clicks Marketing which fires:
Code:
    AddIns.Add "U:\WordGlobals\Marketing", Install:=True
                 OR if you want to toggle
    AddIns("U:\WordGlobals\Marketing.dot").Installed = False
    AddIns("U:\WordGlobals\Marketing.dot").Delete
          etc. etc.
This loads the marketing global with all its procedures, menu items, userforms.....whatever.

And so on.


As these "real" globals are on the network, they can be protected from user changes/access user Permissions; and because they are each ONE file they can be maintained easily. You just need to change that one file, and everyone gets the same thing. Plus the wee global in everyones Startup is just a pointing mechanism, so as long as you do not change the name of the real global files, it never needs much change. Or any.

Gerry
 
1. of course:

AddIns.Add "U:\WordGlobals\Financial", Install:=True
OR if you want to toggle

should be:

AddIns.Add "U:\WordGlobals\Financial.dot", Install:=True
OR if you want to toggle

2. Just to reiterate, suppose you needed to add something (macros, menu items - whatever) to the marketing global. Even if it was just adding one more menu item to something. You edit the marketing.dot file on the network...and you are done. There is no need to change anything for the users.

Gerry
 
Love this. Very elegant. What I copied to user's startup was similar, just a menu item that opens another network .dot that has an auto_open.
 
that opens another network .dot that has an auto_open"

Uh-oh.

Users should never be opening a .dot file. Why are they opening a .dot file? What do you have in the AutoOpen?

BTW; AutoOpen (and AutoNew) are basically old procedures. Ther are, I suppose, a few circumstances where an AutoOpen/AutoNew is appropriate, but I can't think of one right now. They have been replaced by Document_Open, and Document_New.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top