Re: Combobox in Menu Bar Event code
- From: "kaak" <lamkamp@xxxxxxxxx>
- Date: 21 Jun 2006 01:54:30 -0700
Thnx
This will do.
The Purpose of this application is:
I want to give the users a way to import a text file depending on a
accountnumber.
Jeroen
Jean-Guy Marcil wrote:
kaak was telling us:
kaak nous racontait que :
The best thing is an event handler that checks if the text in the
combobox is numeric and of lenghth 6.
But code that runs after hitting the enter key will do fine.
What is the purpose of the application? I must admit I am curious...
I do not think you can have an event handler on a menu, or at least, not
easily.
Meanwhile, play around with this code:
Option Explicit
Private Const strToolBarName = "Menu Bar"
Private Const strCtrlCaption = "Enter number"
Sub AddMenuItem()
Dim oMainMenuBar As Office.CommandBar
Dim objCommandBarComboBox As Office.CommandBarComboBox
'Do not forget to set this according to your need
CustomizationContext = ActiveDocument
Set oMainMenuBar = Application.CommandBars(strToolBarName)
Set objCommandBarComboBox = oMainMenuBar.Controls.Add(msoControlEdit)
With objCommandBarComboBox
.Caption = strCtrlCaption
.OnAction = "CheckInput"
End With
End Sub
Private Sub CheckInput()
Dim myCtrl As Office.CommandBarComboBox
Dim i As Long
Set myCtrl = Application.CommandBars(strToolBarName) _
.Controls(strCtrlCaption)
If Len(myCtrl.Text) = 6 Then
For i = 1 To 6
If Not Mid(myCtrl.Text, i, 1) Like "[0-9]" Then
MsgBox "You must type only numbers."
Exit Sub
End If
Next
MsgBox "You HAVE typed 6 numbers."
Else
MsgBox "You have NOT typed 6 numbers."
End If
End Sub
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@xxxxxxxxxxxxxxxxxxxxxxx
Word MVP site: http://www.word.mvps.org
.
- References:
- Combobox in Menu Bar Event code
- From: kaak
- Re: Combobox in Menu Bar Event code
- From: Jean-Guy Marcil
- Re: Combobox in Menu Bar Event code
- From: kaak
- Re: Combobox in Menu Bar Event code
- From: Jean-Guy Marcil
- Combobox in Menu Bar Event code
- Prev by Date: Re: how to prevent save and copy of MS Word documents
- Next by Date: RE: Problem programmatically opening AutoOpen enabled document
- Previous by thread: Re: Combobox in Menu Bar Event code
- Next by thread: Re: how do i retrieve menubar and toolbar in word
- Index(es):
Relevant Pages
|