We have a macro that creates a new document from a template and then "does stuff" with the resulting document. This used to work fine.
Today, without any apparent cause, the code throws an error. Stepping through the code, I can see that everything works fine, up until the point where I accept the returned object from Documents.Add into a Document variable and try to use that variable (see code). The document is created perfectly, the frmLetter form displays and is processed properly, and all the code in frmLetter runs without error. The end result is an open Letter document, processed like we expect Letter.dot to do.
It's only after the code returns from the call to Documents.Add that the weirdness starts. Apparently, the Documents.Add call does not return an object here.
Any ideas on what might cause this weird behaviour?
'Macro in standard module:
Public Sub CreateLetter()
Dim doc As Word.Document
Set doc = Application.Documents.Add(strWorkgroup & "Letter.dot")
' "Do stuff" with the resulting document:
Call MsgBox(doc.Name) '--> RTE: Object variable or with block variable not Set
' and stepping through the code, I can see that
' the doc variable is indeed Nothing
'Event in Letter.dot:
Private Sub Document_New()
Dim f As frmLetter
Set f = New frmLetter
Set .CurrentDocument = ActiveDocument
'After cmdOK_Click, frmLetter processes its CurrentDocument correctly
Set f = Nothing