Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Set focus on last doc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Senad Isanovic - 19 Mar 2006 18:59 GMT
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"
Helmut Weber - 19 Mar 2006 22:16 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.