Task Pane macro fails (sometimes) 
Author Message
 Task Pane macro fails (sometimes)

Hi,
I've got a Word macro that toggles the Task Pane on/off
and at the same time adjusts the Zoom percentage. (The
built-in Word Command to toggle the Task Pane does not
adjust the Zoom.) The macro fails (except in some cases)
and I don't understand why. This is using Word 2002
(running on XP Pro) but also occurs in the Beta of Word
11.
The macro tests if the Task Pane is already open or not.
If it is open, the macro hides the Task Pane and sets the
Zoom to 125%. If it is already hidden, it shows the Task
Pane and sets the Zoom to "Fit text width".

Here's the macro:

Sub Toggle_TaskPane()
'
    If CommandBars("Task Pane").Visible = True Then
        CommandBars("Task Pane").Visible = False
        ActiveWindow.ActivePane.View.Zoom.Percentage = 125
    Else
       CommandBars("Task Pane").Visible = True
       ActiveWindow.ActivePane.View.Zoom.PageFit =
wdPageFitTextFit
    End If
End Sub

I've written this two different ways: (a) as above, and
(b) the other way around (first test if Task Pane is
hidden). In both cases, the macro fails at the line...

       CommandBars("Task Pane").Visible = True

...but only if the Task Pane is *not* visible the *first
time* the macro is run. If the Task Pane *is* visible the
first time (after Word boots), the macro runs fine for
the rest of that session: I can use it to toggle the Task
Pane on/off with no problems. If the Task Pane is not
visible the first time, the macro just repeatedly fails
(until you manually turn the Task Pane on and run the
macro again).

I can overcome this by an interesting workaround. If I
set Tools/Options/View/Show "Startup Task Pane" to "on",
Word momentarily displays the Task Pane when it boots (it
then turns it off, which is another unexplained thing).
However, this momentary display of the Task Pane is
enough to get the macro working!

I'd be interested to know if this behavior reproduces for
anyone else!
Cheers,
--Alistair



Sat, 17 Sep 2005 22:13:48 GMT  
 Task Pane macro fails (sometimes)
Hi Alistair

It's working for me! What you don't say is what error you're seeing and
where the code is failing.

Also how is the code being triggered?

As for the taskpane momentarily flickering, I would guess that some code is
turning it off, since you've got the SartUp Task Pane option enabled.

Cheers - Peter



Quote:
> Hi,
> I've got a Word macro that toggles the Task Pane on/off
> and at the same time adjusts the Zoom percentage. (The
> built-in Word Command to toggle the Task Pane does not
> adjust the Zoom.) The macro fails (except in some cases)
> and I don't understand why. This is using Word 2002
> (running on XP Pro) but also occurs in the Beta of Word
> 11.
> The macro tests if the Task Pane is already open or not.
> If it is open, the macro hides the Task Pane and sets the
> Zoom to 125%. If it is already hidden, it shows the Task
> Pane and sets the Zoom to "Fit text width".

> Here's the macro:

> Sub Toggle_TaskPane()
> '
>     If CommandBars("Task Pane").Visible = True Then
>         CommandBars("Task Pane").Visible = False
>         ActiveWindow.ActivePane.View.Zoom.Percentage = 125
>     Else
>        CommandBars("Task Pane").Visible = True
>        ActiveWindow.ActivePane.View.Zoom.PageFit =
> wdPageFitTextFit
>     End If
> End Sub

> I've written this two different ways: (a) as above, and
> (b) the other way around (first test if Task Pane is
> hidden). In both cases, the macro fails at the line...

>        CommandBars("Task Pane").Visible = True

> ...but only if the Task Pane is *not* visible the *first
> time* the macro is run. If the Task Pane *is* visible the
> first time (after Word boots), the macro runs fine for
> the rest of that session: I can use it to toggle the Task
> Pane on/off with no problems. If the Task Pane is not
> visible the first time, the macro just repeatedly fails
> (until you manually turn the Task Pane on and run the
> macro again).

> I can overcome this by an interesting workaround. If I
> set Tools/Options/View/Show "Startup Task Pane" to "on",
> Word momentarily displays the Task Pane when it boots (it
> then turns it off, which is another unexplained thing).
> However, this momentary display of the Task Pane is
> enough to get the macro working!

> I'd be interested to know if this behavior reproduces for
> anyone else!
> Cheers,
> --Alistair



Sun, 18 Sep 2005 04:43:15 GMT  
 Task Pane macro fails (sometimes)
Hi Alistair

Also checkout the following link:

http://www.mvps.org/word/FAQs/Customization/ShowTaskPane.htm

I hope this helps + Cheers - Peter



Quote:
> Hi Alistair

> It's working for me! What you don't say is what error you're seeing and
> where the code is failing.

> Also how is the code being triggered?

> As for the taskpane momentarily flickering, I would guess that some code
> is turning it off, since you've got the SartUp Task Pane option enabled.

> Cheers - Peter



>> Hi,
>> I've got a Word macro that toggles the Task Pane on/off
>> and at the same time adjusts the Zoom percentage. (The
>> built-in Word Command to toggle the Task Pane does not
>> adjust the Zoom.) The macro fails (except in some cases)
>> and I don't understand why. This is using Word 2002
>> (running on XP Pro) but also occurs in the Beta of Word
>> 11.
>> The macro tests if the Task Pane is already open or not.
>> If it is open, the macro hides the Task Pane and sets the
>> Zoom to 125%. If it is already hidden, it shows the Task
>> Pane and sets the Zoom to "Fit text width".

>> Here's the macro:

>> Sub Toggle_TaskPane()
>> '
>>     If CommandBars("Task Pane").Visible = True Then
>>         CommandBars("Task Pane").Visible = False
>>         ActiveWindow.ActivePane.View.Zoom.Percentage = 125
>>     Else
>>        CommandBars("Task Pane").Visible = True
>>        ActiveWindow.ActivePane.View.Zoom.PageFit =
>> wdPageFitTextFit
>>     End If
>> End Sub

>> I've written this two different ways: (a) as above, and
>> (b) the other way around (first test if Task Pane is
>> hidden). In both cases, the macro fails at the line...

>>        CommandBars("Task Pane").Visible = True

>> ...but only if the Task Pane is *not* visible the *first
>> time* the macro is run. If the Task Pane *is* visible the
>> first time (after Word boots), the macro runs fine for
>> the rest of that session: I can use it to toggle the Task
>> Pane on/off with no problems. If the Task Pane is not
>> visible the first time, the macro just repeatedly fails
>> (until you manually turn the Task Pane on and run the
>> macro again).

>> I can overcome this by an interesting workaround. If I
>> set Tools/Options/View/Show "Startup Task Pane" to "on",
>> Word momentarily displays the Task Pane when it boots (it
>> then turns it off, which is another unexplained thing).
>> However, this momentary display of the Task Pane is
>> enough to get the macro working!

>> I'd be interested to know if this behavior reproduces for
>> anyone else!
>> Cheers,
>> --Alistair



Sun, 18 Sep 2005 06:46:10 GMT  
 Task Pane macro fails (sometimes)
Thanks Peter!
Nice to have confirmation that the macro does work for
someone! I am triggering the macro through a keyboard
shortcut (I re-assigned Ctrl+T to it). The error message
is:

Runtime error '-2147467259 (80004005)
Method 'Visible' of object 'CommandBar' failed.

Then if I click the Debug button, it takes me to the line
of the macro that says:

CommandBars("Task Pane").Visible = True

Since discovering that the macro runs fine after the Task
Pane has been manually displayed once, and switching on
the option to display the Task Pane by default at
startup, I guess this issue is no longer a problem, just
a curiosity! But if it's working for you, then it must be
something odd about my installation (wouldn't surprise
me!).

Thanks also for the link. According to this, the presence
of an Add-in will stop the Task Pane displaying at
startup. The only Add-in I think I have is one from Adobe
(for creating PDF documents). But even though the Task
Pane doesn't actually remain displayed, it turns on for
long enough to get my macro running!

Thanks again!
Cheers, -- Alistair

Quote:
>-----Original Message-----
>Hi Alistair

>Also checkout the following link:

>http://www.mvps.org/word/FAQs/Customization/ShowTaskPane.
htm

>I hope this helps + Cheers - Peter



>> Hi Alistair

>> It's working for me! What you don't say is what error
you're seeing and
>> where the code is failing.

>> Also how is the code being triggered?

>> As for the taskpane momentarily flickering, I would

guess that some code
Quote:
>> is turning it off, since you've got the SartUp Task

Pane option enabled.
Quote:

>> Cheers - Peter




- Show quoted text -

Quote:

>>> Hi,
>>> I've got a Word macro that toggles the Task Pane
on/off
>>> and at the same time adjusts the Zoom percentage.
(The
>>> built-in Word Command to toggle the Task Pane does
not
>>> adjust the Zoom.) The macro fails (except in some
cases)
>>> and I don't understand why. This is using Word 2002
>>> (running on XP Pro) but also occurs in the Beta of
Word
>>> 11.
>>> The macro tests if the Task Pane is already open or
not.
>>> If it is open, the macro hides the Task Pane and sets
the
>>> Zoom to 125%. If it is already hidden, it shows the
Task
>>> Pane and sets the Zoom to "Fit text width".

>>> Here's the macro:

>>> Sub Toggle_TaskPane()
>>> '
>>>     If CommandBars("Task Pane").Visible = True Then
>>>         CommandBars("Task Pane").Visible = False
>>>         ActiveWindow.ActivePane.View.Zoom.Percentage
= 125
>>>     Else
>>>        CommandBars("Task Pane").Visible = True
>>>        ActiveWindow.ActivePane.View.Zoom.PageFit =
>>> wdPageFitTextFit
>>>     End If
>>> End Sub

>>> I've written this two different ways: (a) as above,
and
>>> (b) the other way around (first test if Task Pane is
>>> hidden). In both cases, the macro fails at the line...

>>>        CommandBars("Task Pane").Visible = True

>>> ...but only if the Task Pane is *not* visible the
*first
>>> time* the macro is run. If the Task Pane *is* visible
the
>>> first time (after Word boots), the macro runs fine
for
>>> the rest of that session: I can use it to toggle the
Task
>>> Pane on/off with no problems. If the Task Pane is not
>>> visible the first time, the macro just repeatedly
fails
>>> (until you manually turn the Task Pane on and run the
>>> macro again).

>>> I can overcome this by an interesting workaround. If
I
>>> set Tools/Options/View/Show "Startup Task Pane"
to "on",
>>> Word momentarily displays the Task Pane when it boots
(it
>>> then turns it off, which is another unexplained
thing).
>>> However, this momentary display of the Task Pane is
>>> enough to get the macro working!

>>> I'd be interested to know if this behavior reproduces
for
>>> anyone else!
>>> Cheers,
>>> --Alistair

>.



Sun, 18 Sep 2005 21:28:06 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. ADO recordset : Resync sometimes works and sometimes failed

2. Adding item to task pane

3. Editing the "Task Pane"

4. Is it possible to create custom Task Panes?

5. Custom Task Pane

6. Customize Task Pane

7. Custom Task Pane

8. Task Pane

9. prevent opening of the task pane

10. Task Pane

11. Developing Task Panes for XP

12. Task Pane via VBA

 

 
Powered by phpBB® Forum Software