D
David
Hi and thanks,
This code works fine in Word97/Win98, and Word2000/XP, but when I try to run
it on Word2002/XP or Word2003/XP it crashes Word totally with a 'problem' in
MSO.dll. According to MSKB, it means corrupted user account, but creating
and running under a new user gives same results. Here's the code:
'1. Get the startup folder
Dim vStartupPath As String
With Dialogs(wdDialogToolsOptionsFileLocations)
.Path = "STARTUP-PATH"
.Update
vStartupPath = .Setting
If Not Right$(vStartupPath, 1) = "\" Then
vStartupPath = vStartupPath + "\"
End If
End With
'-------------------------------------------------
'2. Check if template is loaded and unload it if so.
If Len(Dir(vStartupPath & "Job Finisher.dot")) > 0 Then
AddIns(vStartupPath & "Job Finisher.dot").Installed = False
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal.dot"
End With
End If
'-------------------------------------------------
'3. Check if file is in C:\Documed\blanks and Copy it to the startup folder
If Len(Dir("C:\DocuMed\Blanks\Job Finisher.dot")) > 0 Then
FileCopy "C:\DocuMed\Blanks\Job Finisher.dot", vStartupPath & "Job
Finisher.dot"
MsgBox "'Job Finisher.dot' has been copied to the Startup folder. Click
OK to continue."
Else
MsgBox "'Job Finisher.dot' is not in the C:\Documed\Blanks folder.
Please put it there and reclick the Setup Button."
Exit Sub
End If
'-------------------------------------------------
AddIns.Add FileName:=vStartupPath & "Job Finisher.dot", Install:=True
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal.dot"
End With
'-------------------------------------------------
'5. Create Toolbar button
CustomizationContext = NormalTemplate
Set isThere = CommandBars("Menu Bar").FindControl _
(Type:=msoControlButton, Tag:="Job Finisher")
If isThere Is Nothing Then
With CommandBars("Menu Bar").Controls
Set myButton = .Add(Type:=msoControlButton)
With myButton
.Style = msoButtonCaption
.Caption = "&Job Finisher"
.OnAction = "JobFinisher"
.Tag = "Job Finisher"
End With
End With
MsgBox "'Job Finisher' button added to menu bar."
Else
MsgBox "Update complete."
Exit Sub
End If
MsgBox "Job Finisher shortcut key set to Alt+J."
End Sub
This code works fine in Word97/Win98, and Word2000/XP, but when I try to run
it on Word2002/XP or Word2003/XP it crashes Word totally with a 'problem' in
MSO.dll. According to MSKB, it means corrupted user account, but creating
and running under a new user gives same results. Here's the code:
'1. Get the startup folder
Dim vStartupPath As String
With Dialogs(wdDialogToolsOptionsFileLocations)
.Path = "STARTUP-PATH"
.Update
vStartupPath = .Setting
If Not Right$(vStartupPath, 1) = "\" Then
vStartupPath = vStartupPath + "\"
End If
End With
'-------------------------------------------------
'2. Check if template is loaded and unload it if so.
If Len(Dir(vStartupPath & "Job Finisher.dot")) > 0 Then
AddIns(vStartupPath & "Job Finisher.dot").Installed = False
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal.dot"
End With
End If
'-------------------------------------------------
'3. Check if file is in C:\Documed\blanks and Copy it to the startup folder
If Len(Dir("C:\DocuMed\Blanks\Job Finisher.dot")) > 0 Then
FileCopy "C:\DocuMed\Blanks\Job Finisher.dot", vStartupPath & "Job
Finisher.dot"
MsgBox "'Job Finisher.dot' has been copied to the Startup folder. Click
OK to continue."
Else
MsgBox "'Job Finisher.dot' is not in the C:\Documed\Blanks folder.
Please put it there and reclick the Setup Button."
Exit Sub
End If
'-------------------------------------------------
AddIns.Add FileName:=vStartupPath & "Job Finisher.dot", Install:=True
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal.dot"
End With
'-------------------------------------------------
'5. Create Toolbar button
CustomizationContext = NormalTemplate
Set isThere = CommandBars("Menu Bar").FindControl _
(Type:=msoControlButton, Tag:="Job Finisher")
If isThere Is Nothing Then
With CommandBars("Menu Bar").Controls
Set myButton = .Add(Type:=msoControlButton)
With myButton
.Style = msoButtonCaption
.Caption = "&Job Finisher"
.OnAction = "JobFinisher"
.Tag = "Job Finisher"
End With
End With
MsgBox "'Job Finisher' button added to menu bar."
Else
MsgBox "Update complete."
Exit Sub
End If
MsgBox "Job Finisher shortcut key set to Alt+J."
End Sub