samuelwright
12-08-2005, 07:59 AM
Hey all
Whenever I want to copy a VBA project into the Normal.dot Template, I am allowed to copy the Userforms and Modules across, but not the Microsoft Word Objects ie. the code that is in ThisDocument.
ThisDocument contains Document_Open and Document_Close subs that do not work if I put them in a normal module (unless of course I manual run them-kinda defeats the point of having them run on Document_Open!!).
Is there a way of doing this? Thanks!
The ThisDocument Code is written below:
Sub Document_open()
Dim oCtl As Office.CommandBarControl
Dim oBar As Office.CommandBar
On Error Resume Next
'Loop through all controls to clear all "Subject Naming Utility" buttons
For Each oCtl In oBar.Controls
If oCtl.Caption = "Subject Naming Utility" Then
oCtl.Delete
End If
Next
Set oCtl = Nothing
Dim cb As CommandBarControl
With Application.CommandBars.ActiveMenuBar 'with the main menu bar
Set cb = .Controls.Add(msoControlPopup, Temporary:=True)
With cb 'with the new menu
.Caption = "Subject Name Utility" 'set the caption
.OnAction = "FOI"
End With
End With
End Sub
Sub Document_Close()
Dim cb As CommandBarControl
On Error Resume Next
For Each cb In Application.CommandBars("Menu Bar").Controls
If cb.Caption = "Subject Naming Utility" Then cb.Delete
Next
End Sub
Whenever I want to copy a VBA project into the Normal.dot Template, I am allowed to copy the Userforms and Modules across, but not the Microsoft Word Objects ie. the code that is in ThisDocument.
ThisDocument contains Document_Open and Document_Close subs that do not work if I put them in a normal module (unless of course I manual run them-kinda defeats the point of having them run on Document_Open!!).
Is there a way of doing this? Thanks!
The ThisDocument Code is written below:
Sub Document_open()
Dim oCtl As Office.CommandBarControl
Dim oBar As Office.CommandBar
On Error Resume Next
'Loop through all controls to clear all "Subject Naming Utility" buttons
For Each oCtl In oBar.Controls
If oCtl.Caption = "Subject Naming Utility" Then
oCtl.Delete
End If
Next
Set oCtl = Nothing
Dim cb As CommandBarControl
With Application.CommandBars.ActiveMenuBar 'with the main menu bar
Set cb = .Controls.Add(msoControlPopup, Temporary:=True)
With cb 'with the new menu
.Caption = "Subject Name Utility" 'set the caption
.OnAction = "FOI"
End With
End With
End Sub
Sub Document_Close()
Dim cb As CommandBarControl
On Error Resume Next
For Each cb In Application.CommandBars("Menu Bar").Controls
If cb.Caption = "Subject Naming Utility" Then cb.Delete
Next
End Sub