Hello there
I have an .dot file in the Word 2003 start-folder. When opening word, the file is read. The autoexec-macro should make a new entry with a number of commands and subcommands in the standard menubar. On about 300 PC's this works fine. On a few ones only part of the commands appear. All PC's run W2000 and Office 2003.
Any idea
regards
Jurgen

AutoExec will not execute properly
Joel Triemstra
Ok, i've been working through the code to see what it actually was required to do. You mentioned that the entries menu_protection_set, menu_protection_clear and menu_archive are the only ones that appear within the custom Menubar. Well, those entries are the only ones (next to the "Formulare und Dokumente") who don't to have a IF .. THEN statement which verifies if the required criteria have been met.
If were are walking through the code the following came up:
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 <> ""
This particular IF .. THEN Statement verifies if the Dir(local_start_folder & name_project_list_txt) contains at least 1 file. If a file has been found, the Projektdokumente will be created. If the folder is empty, then it will not create the desired item. During the test, if've changed the value to "C:\" and the item was displayed.
Other then that, the Kundendaten will be visible if mod_customer_data_bas is equal to True, Update Formulare will be visible when update_allowed is not equal to "yes" and Prozeduren if the string value of get_user_name can be found in all_the_gurus via InStr(1, all_the_gurus, get_user_name, vbTextCompare).
My suggestion would be to add "Watches" for each of these values and comparisons to see of the value given actually matches the criteria within the IF ... THEN Statements.
After adjusting the test, mod_customer_data_bas and update allowed to the following constants, all of the items will be displayed:
test = Dir("C:\")
Const mod_customer_data_bas = True
Const update_allowed = "No"
InStr(1, "test", "test", vbTextCompare)
Btw, i've noticed that you've assigned ID 1 to all of the buttons and pop-up menu's. You might want to change that so that every menu and button will have an unique ID. (^_~ )
xluna
your findings are all correct. In the AutoExec I have now added a small delay as shown
Sub AutoExec()
'
' macro is run when AddIn is read in
' the only job is to set the entry in the menubar
'
' we have to wait until Word has done its job
Application.OnTime When:=Now + TimeValue("00:00:03"), _
Name:="start_macro"
End Sub ' AutoExec
Note: the start_macro is as follows:
Sub start_macro()
show_warning = True
Call initialise_program
Call check_if_vpn(False) ' check if connection to server exists
End Sub
with this delay the entries in the menubar show up correctly.
The sub initialise_program is identical in Excel and PowerPoint and executes correctly also on those PC's where the Wordmacro does not.
shangan
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
JCJCJC