Button / Toolbar

G

Guest

Hello,

I have an Add-In with an AutoExec()-Procedure where a Button is added
to the standard-toolbar when Word is opened.

1.) The Problem is that the button will not be deleted after closing
and re-opening word. WHY?? (note: even if temporary:=true)


2.) So I tried first deleting all existing buttons called like the
created one and then adding the button again if neccessary. Here is the
second problem that sometimes word seems not identifiing the existing
button so that there are finally two of them in the toolbar. WHY??
(note: in the situation above where I have no delete-routine every
times I re-open word a new button was added)

Kind Regards,
Nachtigall
 
H

Helmut Weber

Hi Nachtigall,

my theory is, that all and every component of a doc
is available only after an auto-macro has been completed.

For example:

Sub autoexec()
Application.OnTime _
When:=Now + TimeValue("00:00:02"), _
Name:="TellmeWhat"
End Sub

Sub TellmeWhat()
If InStr(ActiveDocument.FullName, "\") Then
MsgBox "Word was started with doc"
Else
MsgBox "Word was not started with doc"
End If
End Sub

The very same applies to changes on commandbars.
The commandbars are often not available,
before the auto-macro has been completed.

I've encountered a similar problem
with positioning commandbars in an autoopen macro.
Word told me, the commandbars weren't existent,
though I could see them on the screen.

I had to move the commands for positioning them
out of the automacro and wait some time before
they became existent, so I could access them.


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Guest

Hi Helmut,

It seems to be a method of resolution solving the problem by deleting
existing buttons via timer.

But I would not even have this problem if the button will be deleted
correctly when word is closing as I set up by using the expression
temorary:=true. Do you know why the button won't disappears?

Regardas,
Nachtigall
 
H

Helmut Weber

Hi Nachtigall,

I don't know. But I have a feeling,
that with autoclose it is the same as with autoopen or autoexec.
Autoclose performs with closing.
Whether before closing or after closing
or when at all is random.

I've found application events like "documentbeforeclose"
more reliable.


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber

Hi,

hmm...

temporary CommandBarControls are something new to me.

It seems it simply doesn't work.

Sorry.

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Guest

Hi Helmut,

But I think that there simply couldn't be an other effect then that the
button is deleted by word after closing if you set
"temporaray:=true"... (Even that books tell the same)

Nachtigall
 
G

Guest

Helmut, something refering to your positing above (27 Aug. 21:59): If I
delete individual buttons in the toolbar out of the Autoexec() you
assumed that it might fail because "all and every component of a doc is
available only after an auto-macro has been completed."

Now I have checked it again. If there is an customized button in the
toolbar when word is starting, I can find this out but the try to
delete it often fails.

To what extent is this matching to you theory, because I can check IF
such a button exists but I can not DELETE it...

Very curious...

Regards,
Nachtigall
 
H

Helmut Weber

Hi Nachtigall,
To what extent is this matching to you theory, because I can check IF
such a button exists but I can not DELETE it...

to a great extent, if I may say so, but it still is a theory.
I forwarded this problem to the MVPs' private groups,
and we'll see, if anyone has a better theory,
or maybe a real explanation.

As to books, hardly ever all of their content was tested.
Except, I'm quite confident, in books, some of the fellow MVPs
have published. :) and ;-)


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Guest

Helmut, why do you think it is consistent that I can indeed check IF a
certain button exists but not delete it at the same moment?

Regards,
Nachtigall
 
K

Klaus Linke

Helmut, why do you think it is consistent that I can indeed check IF
a certain button exists but not delete it at the same moment?


Hi Nachtigall,

Have you set a CommandBarButton object to that button, checked that it is
not "Nothing", and then you can't delete it?
Or what does your code look like?

When you run into problems like this, it's often the customization context
that is to blame.

Either something regarding the customization context went wrong when you
added the button (so it's in a different container than you thought, or
maybe even has been added to several containers [doc, dots]).
Or the customization context changes unexpectedly as you analyse the
problem.

For the first issue, it may be helpful to use FindControls instead of
FindControl, and loop through the results.
FindControl just returns the first control with the given criteria it runs
across, and that may be different at different times.

Regards,
Klaus
 
H

Helmut Weber

Hi,

Cindy Meister told me:
That's correct. This has been "known" to be the case, at
least in Word, for years, now.
I think in Excel it may work differently, since Excel doesn't
have multiple CustomizationContext the way Word does. But
I've never looked into the question in detail.


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Guest

Hi,

Klaus, because I know that my button - if it exists - is added to the
standrd-toolbar, I count its items and loop from "Max downto 1" and
compare each item's caption, and if it matches I delete the according
button. So I have no problems with handling "Noting".

Its good to know Helmut, that there is a fault in Word and exceptional
not at the programmer... Thank you!

Regards,
Nachtigall

Regards,
Nachtigall
 
K

Klaus Linke

Klaus, because I know that my button - if it exists - is added to the
standrd-toolbar, I count its items and loop from "Max downto 1" and
compare each item's caption, and if it matches I delete the according
button. So I have no problems with handling "Noting".


I still think you might have a problem with the customization context.
The controls on your standard toolbar can come from any number of
customization contexts.
Conflicts are resolved as the customizations load.
If you loop over the index i (from controls.count to 1) you can't really be
sure that controls(i) in the loop will return the same control each time.
Its good to know Helmut, that there is a fault in Word and exceptional
not at the programmer... Thank you!

You misunderstood Cindy's reply. It is not a fault in Word. The help to the
Add method clearly states that the Temporary argument is always ignored in
Word. It's simply not necessary or useful in Word.

Regards,
Klaus
 
G

Guest

Hi Klaus,

I don't need to care if control(i) is each time the same one because I
simply compare the caption of each button with the one I gave the
created button.

Who wants to say that nobody needs a temporary button in word but in
excel?

Regards,
Nachtigall
 
K

Klaus Linke

Hi Klaus,

I don't need to care if control(i) is each time the same one because I
simply compare the caption of each button with the one I gave the
created button.

If you have the control with caption XXX in two customization contexts, you
can delete it till you are blue in the face from one of them, and it won't
go away.
I would take bets that this is your problem.

Regards,
Klaus
 

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