View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default US / EN VBA menus

Hi Joël,

Thanks for testing the CommandBars Name property for language. OK, in Excel
it's English in all language versions but for the VBE it's the local
language, learnt something.


I quickly tried your code, it worked once or twice but not always, not sure
why. I don't think you need those Wait's, look into sending and Esc
beforehand. However Sendkeys is often unreliable.

On a vista / 2007 plateform ,it doesn't work properly.


I told you SendKeys doesn't work in Vista in my previous post (it does work
in a fully compiled VB6 app). There are various ways to simulate SendKeys
with API's, you could look into the SendInput and keybd_event Lib APIs. Keep
in mind you also need to send key-down and key-up events before/after the
keystroke with these APIs. I suggested following in another thread -

--------------------------------------------------------------------------------
Karl Peterson has provided an excellent replacement for SendKeys

http://vb.mvps.org/samples/project.asp?id=sendinput


Import the bas module MSendInput into your VBA project. This was written for
VB5/6 so some minor changes for VBA:


- add the following constant definitions at the top of the module
Const vbShiftMask = 1&
Const vbKeyScrollLock = 145&


- find and comment any lines starting Debug.Print


- remove
#If Not VB6 Then
Private Function Split etc


though if you need to cater for Excel97 you'll need to do something like
this
' Break into pieces, if possible.
#If VBA6 Then
pieces = Split(this, " ")
#Else
pieces = Split97(this, " ")
' Karl's VB5 function needs a little adaptation for Excel97
#End If
------------------------------------------------------------------------------------

Note this alternative also simulates key-strokes, you still have the same
problem of needing to ensure your window or dialog is active. As I mentioned
in an earlier post it is possible to control all the dialogs using API
methods, without SendKeys or equivalent. But it's a lot of work.

Regards,

Peter T



"jojo" wrote in message
...
Hi ! Peter !

Back again to review some item...

The test you asked workes for Worksheets Application.CommandBars, but not
for VBE.CommandBars (Name and NameLocal are both French names)

But using VBE.CommandBars(1) ik OK

The following code works fine on 2000 Plateform (I suppose is OK on 2003
too)

Set ctr = .VBE.CommandBars.FindControl(ID:=2578)
ctr.Execute
.Wait (Now + TimeValue("0:00:5"))
.SendKeys "^{TAB}", True
.Wait (Now + TimeValue("0:00:3"))
.SendKeys "{+}", True
.SendKeys "{TAB}", True
.SendKeys "SGS2009", True
.Wait (Now + TimeValue("0:00:1"))
.SendKeys "{TAB}", True
.SendKeys "SGS2009", True
.ScreenUpdating = True
'Stop
.Wait (Now + TimeValue("0:00:10"))
.SendKeys "{ENTER}", True

On a vista / 2007 plateform ,it doesn't work properly.
If I delete the " ' " to execute the "Stop" Command, the dalogBox
VBEProject Properties is correctly displayed with all the infomations
sent,
and typiing the enter key make the workbook correctly protected.

Without the stop command, the workbook is not protected... There is no
error
message !!! the entire code is executed without problem, but no
protection.

I hope my explainations are OK for you,

regards,

Joël

"Peter T" wrote:

typo, missing "in"

There are various API methods to trigger or set all the controls IN
that
dialog (and the other dialogs and msgbox's that might appear)


Peter T