I have several documents open. I double-click on Letter.dot to create a new
document based on that template. Letter.dot contains a UserForm that I fill
in and then click Ok button. Now the active document is switched to some of
others documents, after that I have to use Alt Tab to switch back to my
"letter" document. How can I avoid this? I want focus to be on my new letter
doc then clicking Ok button. I tried using document variables but I can't
figure out how to do.
ActiveDocument.Variables.Add("docType") = "Letter"
Hi Senad,
what does the OK-button do?
I can't think of a reason for Word,
to change the activedocument without being told so.
Unless you close an activedocument with some other docs present.
When having many docs open, it seems,
Word is keeping track of the opening time
and jumps to the one, that was second last
if the last one is closed.
Or it uses the time of last saving.
Could be different in different Word-versions.
But this is mere speculation.
Maybe someone else knows.

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
red6000 - 19 Mar 2006 22:53 GMT
I had exactly the same problem. Worked fine with Word 97, but then upgraded
Word and loses focus on Word XP and Word 2003 if you already have word docs
open.
Only way I have got around it is by not using templates but read only docs
(as though they are templates) and then use the code:
Documents("BaseLetter.doc").Activate
to regain the focus.
I'd love to know if there is another way!
> Hi Senad,
>
[quoted text clipped - 16 lines]
>
> Maybe someone else knows.
Helmut Weber - 19 Mar 2006 23:19 GMT
Or
Dim oDoc As Document
Set oDoc = ActiveDocument
' whatever, except closing oDoc
oDoc.Activate

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Senad Isanovic - 20 Mar 2006 09:29 GMT
OK-button just opens en new doc based on my template, and does nothing
more..
Documents.Add TemplFileName
> Hi Senad,
>
[quoted text clipped - 16 lines]
>
> Maybe someone else knows.
Robert Paulsen - 21 Mar 2006 02:34 GMT
You can also combine your code with Helmut Weber's:
Dim oDoc As Document
Set oDoc = Documents.Add(TemplFileName)
' whatever, except closing oDoc
oDoc.Activate
> OK-button just opens en new doc based on my template, and does nothing
> more..
[quoted text clipped - 21 lines]
> >
> > Maybe someone else knows.