Hi
the series of macros must run in Word, Excel and Powerpoint. Therefore individual start modules exist for the three applications calling then the common Sub initialise_program
here is the code
in Module "Main"
Sub AutoExec()
'
' macro is run when AddIn is read in
' the only job is to set the entry in the menubar
'
Call initialise_program()
End Sub ' AutoExec
Module mod_initialise_form_menu
Sub remove_commandbar_entry()
Dim xx, my_bar As Object
Set my_bar = CommandBars.ActiveMenuBar
' remove existing entry (may be more than one!)
For Each xx In my_bar.Controls
If xx.Caption = menu_forms Then
my_bar.Controls(xx.Caption).Delete
End If ' xx.Caption = menu_forms
Next xx ' Each xx In my_bar.Controls
End Sub
Sub initialise_program()
'
'
' Adds the menue to the menubar
'
Dim xx, cmd, my_bar, new_menu As Object
Dim cmd_sub As CommandBarControl
Dim aa As String
Dim yy, entry_nr As Long
Dim test As String, is_here As String
'
' get language dependent texts
'
If init_them_variables(True) = False Then Exit Sub
'
' remove possibly existing CommandBar entry
'
Call remove_commandbar_entry
'
' find " " so that new entry position can be defined
yy = 0
Set my_bar = CommandBars.ActiveMenuBar
For Each xx In my_bar.Controls
yy = yy + 1
If xx.Caption = "& " Then
Exit For
End If ' xx.Caption = "& "
Next xx ' Each xx In my_bar.Controls
' check if word
If InStr(1, Application.Name, "word", vbTextCompare) > 0 Then
Set new_menu = my_bar.Controls.Add(Type:=msoControlPopup, before:=yy)
Else ' InStr(1, Application.Name, "word", vbTextCompare) > 0
Set new_menu = my_bar.Controls.Add(Type:=msoControlPopup, before:=yy, Temporary:=True)
End If ' InStr(1, Application.Name, "word", vbTextCompare) > 0
new_menu.Caption = menu_forms
'
Set cmd = new_menu.Controls.Add(Type:=msoControlButton, Id:=1)
cmd.Caption = menu_forms_and_documents '"&Formulare und Dokumente"
cmd.TooltipText = "Formulare und Dokumente"
cmd.Style = msoButtonCaption
cmd.OnAction = "get_form"
test = Dir(local_start_folder & name_project_list_txt)
If test <> "" Then
Set cmd = new_menu.Controls.Add(Type:=msoControlButton, Id:=1)
cmd.Caption = menu_projects ' "&Projektdokumente"
cmd.TooltipText = "Formulare und Dokumente"
cmd.Style = msoButtonCaption
cmd.OnAction = "Select_Project_Document"
End If ' test <> ""
Set cmd = new_menu.Controls.Add(Type:=msoControlPopup, Id:=1)
cmd.Caption = menu_file_management ' "&Dateimanagement"
cmd.TooltipText = ""
'
Set cmd_sub = cmd.Controls.Add(Type:=msoControlButton, Id:=1)
cmd_sub.Caption = menu_protection_set '"Schreibschutz &setzen"
cmd_sub.TooltipText = ""
cmd_sub.Style = msoButtonCaption
cmd_sub.OnAction = "file_release"
'
Set cmd_sub = cmd.Controls.Add(Type:=msoControlButton, Id:=1)
cmd_sub.Caption = menu_protection_clear '"Schreibschutz &entfernen"
cmd_sub.TooltipText = ""
cmd_sub.Style = msoButtonCaption
cmd_sub.OnAction = "remove_write_protect"
Set cmd_sub = cmd.Controls.Add(Type:=msoControlButton, Id:=1)
cmd_sub.Caption = menu_archive '"Datei &archivieren"
cmd_sub.TooltipText = ""
cmd_sub.Style = msoButtonCaption
cmd_sub.OnAction = "archive_document"
'
' check if mod_customer_data is ok, if not, don't show menu_client_data
'
If mod_customer_data_bas = True Then
Set cmd = new_menu.Controls.Add(Type:=msoControlPopup, Id:=1)
cmd.Caption = menu_client_data ' "&Kundendaten"
cmd.TooltipText = ""
'
Set cmd_sub = cmd.Controls.Add(Type:=msoControlButton, Id:=1)
cmd_sub.Caption = menu_client_data_enter '"&Neue Kundendaten eingeben"
cmd_sub.TooltipText = ""
cmd_sub.Style = msoButtonCaption
cmd_sub.OnAction = "enter_new_customer_data"
'
Set cmd_sub = cmd.Controls.Add(Type:=msoControlButton, Id:=1)
cmd_sub.Caption = menu_client_data_change ' "&Aktuelle Kundendaten andern"
cmd_sub.TooltipText = ""
cmd_sub.Style = msoButtonCaption
cmd_sub.OnAction = "change_customer_data"
'
Set cmd_sub = cmd.Controls.Add(Type:=msoControlButton, Id:=1)
cmd_sub.Caption = menu_client_data_insert '"&In Formular einfugen"
cmd_sub.TooltipText = ""
cmd_sub.Style = msoButtonCaption
cmd_sub.OnAction = "insert_customer_data"
End If ' Application.Name <> "Microsoft PowerPoint"
If update_allowed <> "yes" Then
Set cmd = new_menu.Controls.Add(Type:=msoControlButton, Id:=1)
cmd.Caption = menu_update_forms ' "&Update Formulare"
cmd.TooltipText = "Update Formulare"
cmd.Style = msoButtonCaption
cmd.OnAction = "menue_get_new_files"
End If ' update_allowed <> "yes"
'
' test if Guru is here
'
If InStr(1, all_the_gurus, get_user_name, vbTextCompare) > 0 Then
Set cmd = new_menu.Controls.Add(Type:=msoControlPopup, Id:=1)
cmd.Caption = menu_procedures ' "&Prozeduren"
cmd.TooltipText = ""
'
Set cmd_sub = cmd.Controls.Add(Type:=msoControlButton, Id:=1)
cmd_sub.Caption = menu_procedures_save ' "&Save Procedure"
cmd_sub.TooltipText = ""
cmd_sub.Style = msoButtonCaption
cmd_sub.OnAction = "archive_procedure"
End If ' InStr(1, all_the_gurus, get_user_name, vbTextCompare) > 0
End Sub
======= end of code ========
In the cases were the macro does not execute properly only the entries menu_protection_set, menu_protection_clear and menu_archive appear in the menubar
Hope this helps!
regards
Jurgen