Set focus on last doc

S

Senad Isanovic

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"
 
H

Helmut Weber

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.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

red6000

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!
 
H

Helmut Weber

Or

Dim oDoc As Document
Set oDoc = ActiveDocument
' whatever, except closing oDoc
oDoc.Activate

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
S

Senad Isanovic

OK-button just opens en new doc based on my template, and does nothing
more..

Documents.Add TemplFileName
 
R

Robert Paulsen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top