Okie Dokie,
The code window opens because "makros enabled" is not enabled on all users desktops. When the form opens, it is trying to read from your Doc_Open event. If makros id disabled, it can not open the document, hence the code window to enable the makros.
You can do two things here -
1) Enable makros on all users pc's or try the following to open your document -
Private Sub oApp_DocumentOpen(ByVal Doc As Document)
combo.AddItem "Jan."
End Sub
2)Do it automatically, which is a bit more advanced, but the code is set at public level, which means that ANY document that is opened by the user will be opened with makros enabled.
If you create a DocumentChange event and store it in an Addin, it will be triggered when any document is created, opened, closed or the focus changes from one document to another. You can take advantage of this to simulate AutoNew, AutoOpen, AutoClose macros (as well as being able to monitor when the focus changes). Unlike the application event DocumentChange, AutoNew, AutoOpen and AutoClose macros only behave globally if stored in Normal.dot.
It will also auto load the document with all the code read perfectly. Have a look at the code below -
In a Module: (Name the module what you like)
Option Explicit
Dim oAppClass As New ThisApplication
Public oldNoOfOpenDocs As Long
Public FirstNewDoc As Boolean
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
oldNoOfOpenDocs = 0
FirstNewDoc = True
End Sub
In a Class Module (name this ThisApplication)!!!!!
Option Explicit
Public WithEvents oApp As Word.Application
Private Sub oApp_DocumentChange()
On Error GoTo ExitCode
Dim newNoOfOpenDocs As Long
Dim docAdded As Boolean
Dim docClosed As Boolean
newNoOfOpenDocs = Application.Documents.Count
If newNoOfOpenDocs > oldNoOfOpenDocs Then
docAdded = True
If ActiveDocument.Name = "Document1" And FirstNewDoc Then
FirstNewDoc = True
Else
FirstNewDoc = False
End If
oldNoOfOpenDocs = oldNoOfOpenDocs + 1
ElseIf oldNoOfOpenDocs > newNoOfOpenDocs Then
docClosed = True
FirstNewDoc = False
oldNoOfOpenDocs = oldNoOfOpenDocs - 1
End If
If docAdded Then
If Len(ActiveDocument.Path) = 0 Then
Call PsuedoAutoNew
Else
Call PsuedoAutoOpen
End If
ElseIf docClosed Then
Call PsuedoAutoClose
ElseIf FirstNewDoc Then
If Len(ActiveDocument.Path) = 0 Then
Call PsuedoAutoNew
Else
Call PsuedoAutoOpen
End If
Else
Call DocChangedFocus
End If
Exit Sub
ExitCode:
End Sub
Private Sub PsuedoAutoNew()
'Your code here
End Sub
Private Sub PsuedoAutoOpen()
combo.AddItem "Jan." 'and so on...
End Sub
Private Sub PsuedoAutoClose()
'Your code here
End Sub
Private Sub DocChangedFocus()
'Your code here
End Sub
In one important respect, the PsuedoAutoNew and PsuedoAutoOpen macros work better than the Word specific NewDocument and DocumentOpen events.
When you start Word, a new blank document is created; the PsuedoAutoNew macro runs, but neither AutoNew nor the NewDocument events are triggered.
Similarly, if you start Word with an AutoExec macro that opens a document, or that allows the user to open a document, for example:
Public Sub AutoExec()
Dim myFile As String
myFile = Application.RecentFiles(1).Path & "\" _
& Application.RecentFiles(1).Name
Documents.Open myFile
End Sub
... AutoOpen and the PsuedoAutoOpen macro both fire.
I hope this is helping...;)