Re: switching focus by Russ
Russ
Thu Sep 14 03:37:41 CDT 2006
Lloyd,
> You need to use Application.Activate, not ThisDocument.Activate.
Especially not ThisDocument, since ThisDocument may refer to a underlying
template containing vba modules that created your currently open working,
non-template document. So if your template wasn't currently open in Word for
editing, then ThisDocument.activate would not bring the template or any
other document to the forefront.
Below is quote from VBA Help:
"Activate Method Example
This example activates the document named "Sales.doc."
Documents("Sales.doc").Activate
This example activates the next window in the Windows collection.
ActiveWindow.Next.Activate
This example splits the active window and then activates the first pane.
With ActiveWindow
.SplitVertical = 50
.Panes(1).Activate
End With"
I thought you would read that and choose the first example and activate your
working document by name, assuming that you had captured the name earlier
with ActiveDocument.Name when it did have focus.
>
> --
> Enjoy,
> Tony
>
> "Lloyd" <Lloyd@discussions.microsoft.com> wrote in message
> news:D1163861-4E80-44DA-A5CF-E2C4DE344FE4@microsoft.com...
>> Russ,thanks for offering a thought on this. Actually, the .activate
> method
>> was one of the first things I tried. But I've not been successful with
> it.
>> I believe the .activate method isn't working because it seems that the
> form
>> is part of the same object that the activate method is being called from,
>> such as "ThisDocument.Activate". And ithe activate method doesn't seem to
> be
>> able to distinguish between different parts of the "ThisDocument" object.
> So
>> it appears the activate method is merely refreshing the focus on whatever
>> already has the focus in the active window, namely the form.
>>
>> Perhaps an API call is necessary here. I'm playing around with some code
>> for that at present. If I come up with anything that works I'll be sure
> to
>> post it. Nevertheless, I do appreciate your input and any other thoughts
> you
>> might have on the subject.
>>
>> Lloyd
>>
>> "Russ" wrote:
>>
>>> Hi Lloyd,
>>>
>>> Doesn't the .activate method return focus to the document?
>>> The .goto method navigates footnotes and other document features.
>>> So after using Doug's suggestion, you could have the document
> automatically
>>> activated and gone to the footnote it inserted.
>>>
>>>> Thanks for your suggestion Doug. Unfortunately this only delays the
> point at
>>>> which the user has to make that extra click to activate the document
> window,
>>>> as the form is there only to to provide tools for the user while they
> work
>>>> directly in the document.
>>>>
>>>> What I'm trying to achieve is a seamless ongoing use of the commands
> on the
>>>> form while working in the document, without having to click back into
> the
>>>> document everytime you need use a command.
>>>>
>>>> Thanks anyway. Your suggestion was greatly appreciated.
>>>>
>>>> Lloyd
>>>>
>>>> "Doug Robbins - Word MVP" wrote:
>>>>
>>>>> Another way to do it would be to have the button display an input box
> into
>>>>> which the user enters the data for the footnote and when the click on
> OK in
>>>>> the input box what they entered into the input box would be placed
> into a
>>>>> footnote.
>>>>>
>>>>> --
>>>>> Hope this helps.
>>>>>
>>>>> Please reply to the newsgroup unless you wish to avail yourself of my
>>>>> services on a paid consulting basis.
>>>>>
>>>>> Doug Robbins - Word MVP
>>>>>
>>>>> "Lloyd" <Lloyd@discussions.microsoft.com> wrote in message
>>>>> news:E6257A3D-AEC0-4474-A7AA-1AC31F0F473A@microsoft.com...
>>>>>> I should add a couple of other bits of information in case it's
> helpful:
>>>>>> 1. The form is running in a modeless state
>>>>>> 2. I'm trying not to have to close the form in order to return the
> focus
>>>>>> the active document window, since that means adding code to show the
> form
>>>>>> again once the user has completed their immediate task, and the form
> is
>>>>>> essentially a custom made toolbar which I want to keep open all the
> time
>>>>>> while the document is open.
>>>>>> 3. The current situation requires the user to physically click in
> the
>>>>>> active document window after running any of the utilities on from
> the form
>>>>>> before they can actually continue working in the document. This is
> makes
>>>>>> it
>>>>>> less intuitive to the user and slows the process down.
>>>>>> Thanks again for any suggestions on this.
>>>>>>
>>>>>> Lloyd
>>>>>>
>>>>>> "Lloyd" wrote:
>>>>>>
>>>>>>> I have created a userform in Word using VBA with several command
> buttons
>>>>>>> on
>>>>>>> the form. One of the command buttons on the form inserts a custom
>>>>>>> footnote.
>>>>>>> While the code works perfectly well, the command button on the form
>>>>>>> continues
>>>>>>> to keep the focus, not the newly created footnote, where the user
> is
>>>>>>> supposed
>>>>>>> to enter their text. Is there a routine I can call to set the
> focus to
>>>>>>> the
>>>>>>> document window where the selection is so the user can
> automatically
>>>>>>> start
>>>>>>> typing the footnote text immediately after clicking on the command
> button
>>>>>>> on
>>>>>>> the user form?
>>>>>>>
>>>>>>> Thanks for any help.
>>>>>>>
>>>>>>> Lloyd
>>>>>
>>>>>
>>>>>
>>>
>>> --
>>> Russ
>>>
>>> drsmN0SPAMikleAThotmailD0Tcom.INVALID
>>>
>>>
>
>
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID