How to Activate newly created documents in Word 2000

Article contributed by Perry de Lima
 

Word 2000 is SDI orientated.

SDI = Single Document Interface, in other words: every child has a parent….

To work-around the problem of not being able to activate newly created documents from a userform, you’ll have to force your OS to activate the parent of newly created documents, assisted by a couple of API calls, as opposed to trying to get MS Word to activate the newly created document itself.

The code below exemplifies two API functions declared locally in the general declaration section of a userform, and the use of the cmdOK’s click event to create the new document, unload itself and activate this newly created document, regardless how many SDI instances are running.

Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long

Private Sub cmdOK_Click()

Dim sTemplate As String
Dim d As Word.Document
Dim l As Long

sTemplate = “d:\Docs\A_Template.dot”
    'Create a new document
    Set d = Documents.Add(sTemplate

     '<rest of the code goes here>

  'Avoid SetFocus() API to return the userform windowhandle
     Unload Me

 
'Activate the parent window of the newly created doc (SDI)
    d.Parent.Activate

 
'Force your OS to activate the currently active window
     l = SetFocus(GetActiveWindow())

End Sub


Click to view Terms of Use page

Click to view Disclaimer page