S
Scott Brogan
HELP - Thank you in advance for your help.
I have what I think is a simple requirement but I've run out of ideas.
1) create a simple edit box and a button on a toolbar in office (excel, word, etc.,)
2) enter a value into the edit box
3) click on the button
4) retrieve the value from the edit box
NOTE: I've noticed that the value in the edit box does not persist unless I enter the text and hit "TAB" or "ENTER" to 'store' the value into the box. When I click on a another control, the value immediately disappears. I've tried to capture the data using with events as described in the link below but only a few events are available (and the value in the edit box disappears before I can capture it).
http://msdn.microsoft.com/library/d...ore/html/deovrworkingwithcommandbarevents.asp
Can anybody please help me capture the value from the edit box when focus is lost to another control in the app? I want the behavior of the edit box and button to be similar to a simple edit box and button on a form (i.e., persist the data entry).
Here is the sample code I've been experimenting with. I've tried calling two different functions using .onaction (InvokeMessageBox and InvokeMessageBox1 respectively) but they only capture the empty edit box.
Sub CreateOfficeBar()
Dim cbrCommandBar As CommandBar
Dim cbcCommandBarButton As CommandBarButton
Dim cbcCommandBarTextBox As CommandBarComboBox
On Error Resume Next
Application.CommandBars("Office Bar Sample").Delete
Set cbrCommandBar = Application.CommandBars.Add
cbrCommandBar.Name = "Office Bar Sample"
With cbrCommandBar.Controls
Set cbcCommandBarTextBox = .Add(msoControlEdit)
With cbcCommandBarTextBox
.Tag = "EditBox"
End With
Set cbcCommandBarButton = .Add(msoControlButton)
With cbcCommandBarButton
.Caption = "Click Me"
.Style = msoButtonCaption
.OnAction = "InvokeMessageBox"
.Tag = cbcCommandBarTextBox.Text
End With
End With
cbrCommandBar.Visible = True
End Sub
Function InvokeMessageBox()
Dim MessageBoxValue As String
Dim ctl As CommandBarControl
For Each ctl In CommandBars("Office Bar Sample").Controls
If ctl.Tag = "EditBox" Then
MessageBoxValue = Trim(ctl.Text)
End If
Next ctl
MsgBox MessageBoxValue
End Function
Function InvokeMessageBox1()
Dim ctl As CommandBarControl
Set ctl = Application.CommandBars.ActionControl
MessageBoxValue = ctl.Tag
MsgBox MessageBoxValue
End Function
Thank you very much!
Scott
I have what I think is a simple requirement but I've run out of ideas.
1) create a simple edit box and a button on a toolbar in office (excel, word, etc.,)
2) enter a value into the edit box
3) click on the button
4) retrieve the value from the edit box
NOTE: I've noticed that the value in the edit box does not persist unless I enter the text and hit "TAB" or "ENTER" to 'store' the value into the box. When I click on a another control, the value immediately disappears. I've tried to capture the data using with events as described in the link below but only a few events are available (and the value in the edit box disappears before I can capture it).
http://msdn.microsoft.com/library/d...ore/html/deovrworkingwithcommandbarevents.asp
Can anybody please help me capture the value from the edit box when focus is lost to another control in the app? I want the behavior of the edit box and button to be similar to a simple edit box and button on a form (i.e., persist the data entry).
Here is the sample code I've been experimenting with. I've tried calling two different functions using .onaction (InvokeMessageBox and InvokeMessageBox1 respectively) but they only capture the empty edit box.
Sub CreateOfficeBar()
Dim cbrCommandBar As CommandBar
Dim cbcCommandBarButton As CommandBarButton
Dim cbcCommandBarTextBox As CommandBarComboBox
On Error Resume Next
Application.CommandBars("Office Bar Sample").Delete
Set cbrCommandBar = Application.CommandBars.Add
cbrCommandBar.Name = "Office Bar Sample"
With cbrCommandBar.Controls
Set cbcCommandBarTextBox = .Add(msoControlEdit)
With cbcCommandBarTextBox
.Tag = "EditBox"
End With
Set cbcCommandBarButton = .Add(msoControlButton)
With cbcCommandBarButton
.Caption = "Click Me"
.Style = msoButtonCaption
.OnAction = "InvokeMessageBox"
.Tag = cbcCommandBarTextBox.Text
End With
End With
cbrCommandBar.Visible = True
End Sub
Function InvokeMessageBox()
Dim MessageBoxValue As String
Dim ctl As CommandBarControl
For Each ctl In CommandBars("Office Bar Sample").Controls
If ctl.Tag = "EditBox" Then
MessageBoxValue = Trim(ctl.Text)
End If
Next ctl
MsgBox MessageBoxValue
End Function
Function InvokeMessageBox1()
Dim ctl As CommandBarControl
Set ctl = Application.CommandBars.ActionControl
MessageBoxValue = ctl.Tag
MsgBox MessageBoxValue
End Function
Thank you very much!
Scott