"Edit Text" Event?

J

J. Mitchell

When text is being edited in MS-Project (also in other MS-Office
applications -- Excel etc.) many methods will
not work (error if called); the *default* toolbars are also greyed.

However, my *custom* toolbar is not greyed, and the user can click the
button and launch my code -- which will fail in such a state.

What signals this state? I want my code to be able to avoid those errors.
TIA!
 
H

Haris Rashid

hi Mitchell,

you can use the "enable" property at run time to enable or disable a button.
You can set the button disabled (Enable=False) as default and use the
ToolBar.Button.Enable property in the code module where the button should be
active.

Regards,
Haris
 
J

J. Mitchell

No, I don't want to disable the button, I know how to do *that*.
My question is how to tell whether the code will fail due to text being
edited (so that I can manually have my custom toolbar disabled along with
the rest of the standard toolbars...)
Otherwise the button should always be active, just like normal MS-Office
buttons.
 
R

Rod Gill

I don't believe there is an event to capture the fact someone is editing a
cell, or indeed a flag to indicate such. Your best bet is teach them not to
by at the beginning of you code using SendKeys to send one or two ESC keys
to cancel the edit. They won't do it again!!
 
H

Haris Rashid

hi Mitchell,

you can add error handling code in the module that triggers the error. When
the error occurs, the error handling routine will be called. Within this code
you can take appropriate action to respond to the user that the command
button is not available and exit by hiding, or temporarily disabling the
button. Disabling means that you should enable it in the code where this
button is required and likely to be cliked for appropriate action.

Regards,

Haris.
--------
 
E

Earl Lewis

What you're being told here is that there is no native method exposed in the MSProject VBA object model that will allow you to detect this application state. I've looked for similar events and have found nothing. If you're still not convinced you can open a support ticket with M$.

Earl
Ugh, can't say I like that "solution" at all...
I know this is possible since I've seen other add-ins do that.
 
J

J. Mitchell

This is a workaround that does not actually handle the situation.
Certainly there is a way to know that Project is in edit mode...
 
J

J. Mitchell

Ugh, can't say I like that "solution" at all...
I know this is possible since I've seen other add-ins do that.
 
J

J. Mitchell

Earl:
I know there is no "easy" way to detect this state (otherwise I wouldn't be
here asking...)
Nevertheless, this *is* possible since I've seen other add-ins do just that.
There is probably some creative workaround for this... suggestions?


Earl Lewis said:
What you're being told here is that there is no native method exposed in
the MSProject VBA object model that will allow you to detect this
application state. I've looked for similar events and have found nothing. If
you're still not convinced you can open a support ticket with M$.
 
L

Lars Hammarberg

Hi!
Suppose your commandbar is called "MyCommandbar".
When editing text, Project disables the Save-button amongst others - this
button has an Id=3.

Create a class called "Class1"
Put this code in there:

Public WithEvents br As Office.CommandBars
Public mycommandbar As Office.CommandBar

Private Sub br_OnUpdate()
'This will comletely hide the entire "MyCommandbar" when editing text.
'You could set the Enabled property for each control on your commandbar
'instead if you want exactly the same appearance as the "ordinary" bars.
mycommandbar.Enabled = br.FindControl(ID:=3).Enabled
End Sub



Call the class from another module like this:

Dim cl As Class1
Sub startthis()
Set cl = New Class1
Set cl.br = CommandBars
Set cl.mycommandbar = CommandBars("MyCommandbar")
End Sub
Sub stopthis()
Set cl.br = Nothing
Set cl.mycommandbar = Nothing
Set cl = Nothing
End Sub
 
J

J. Mitchell

OK... very simple (once you know how...)
Just do: CommandBarControls.Add(EmptyParam, 40001, EmptyParam, EmptyParam,
Temporary);
And yes, Type need not be defined.
IDs such as 40001 work fine. 40000 is probably some MS-Office constant...
can't find any reference for that though, but...
Bottom line: your new control is now "builtin", and will thus be disabled by
Office when needed :D

Lars: I haven't tested this, but I doubt your solution will work if the
commandbars are not visible.
 
E

Earl Lewis

J. Mitchell,

I'm very interested in your solution. Maybe you could share a more complete code sample and explanation with us?

I tried your one-liner but encountered various errors (object required and subscript out of range). Apparently there's more to the solution than that one line of code.

Earl
OK... very simple (once you know how...)
Just do: CommandBarControls.Add(EmptyParam, 40001, EmptyParam, EmptyParam,
Temporary);
And yes, Type need not be defined.
IDs such as 40001 work fine. 40000 is probably some MS-Office constant...
can't find any reference for that though, but...
Bottom line: your new control is now "builtin", and will thus be disabled by
Office when needed :D

Lars: I haven't tested this, but I doubt your solution will work if the
commandbars are not visible.
 
J

J. Mitchell

Actually there isn't anything else really... but here is the routine (Delphi
code):

procedure _CommandBarButton(const prjCommandBarControls: CommandBarControls;
const Caption: string; const AlwaysEnabled: Boolean);
var
ID: Integer;
prjCommandBarButton: CommandBarButton;
begin
if AlwaysEnabled then ID := 1 else ID := 40001;
prjCommandBarButton := prjCommandBarControls.Add(EmptyParam, ID,
EmptyParam,
EmptyParam, True) as CommandBarButton;
prjCommandBarButton.Caption := Caption;
prjCommandBarButton.Style := msoButtonCaption;
end;

Note that you *must* have a Caption set or you'll get errors (that is
probably your problem -- but this applies to adding buttons in general,
regardless of Type, ID, etc.)
E.g., in VB:
.Add(...)
will fail but
.Add(...).Caption("...")
works.



Earl Lewis said:
J. Mitchell,

I'm very interested in your solution. Maybe you could share a more
complete code sample and explanation with us?
I tried your one-liner but encountered various errors (object required and
subscript out of range). Apparently there's more to the solution than that
one line of code.
 

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