PC Review


Reply
Thread Tools Rate Thread

CommandBarComboBox : AddItem - procedure to attach routine.

 
 
=?Utf-8?B?S3VsaW4=?=
Guest
Posts: n/a
 
      10th Nov 2007
Question :
=======
Exact syntax required when clicking/selecting AddItem 1 , I can invoke the
following Sub ShowExpenses()
Worksheets("Data").Select
End Sub


, on selecting AddItem 2, I can invoke the

Sub ShowSales()
Worksheets("Facility").Select
End Sub

and on selecting AddItem 3, I can invoke the following

Sub ShowPurchases()
Worksheets("Segment").Select
End Sub


Bye the way , I am little bit novice for VBA-EXCELL.





My entire procedure start from here :
========================



Sub CreateNewToolBar()
'the next two lines are only required during development
On Error Resume Next
CommandBars("Accounts").Delete

Dim NewMenuBar As CommandBar
Dim NewButton As CommandBarButton

Set NewMenuBar = CommandBars.Add("Accounts")

Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
CommandBars("View").Controls("Normal").ID)
NewButton.Caption = "&Normal"
NewButton.Style = msoButtonIconAndCaptionBelow

Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
CommandBars("View").Controls("Page Break Preview").ID)
NewButton.Caption = "&Preview"
NewButton.Style = msoButtonIconAndCaption

Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
NewButton.Caption = "&Data"
NewButton.Style = msoButtonCaption
NewButton.OnAction = "ShowExpenses"

Dim NewComboboxButton As CommandBarComboBox
Set NewComboboxButton = NewMenuBar.Controls.Add(msoControlComboBox)
NewComboboxButton.Caption = "&Segment"
NewComboboxButton.OnAction = "ShowPurchases"
With CommandBars("Accounts").Controls(4)
.AddItem "Item 1", 1
.AddItem "Item 2", 2
.AddItem "Item 3", 3
.DropDownLines = 3
.ListIndex = 1
End With



Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
NewButton.Caption = "&Facility"
NewButton.Style = msoButtonCaption
NewButton.OnAction = "ShowSales"

Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
NewButton.Caption = "&E&xit"
NewButton.OnAction = "RestoreExcelMenuBar"
NewButton.Style = msoButtonCaption

Worksheets("AccountsSheet").Select
NewMenuBar.Visible = True
End Sub

Sub ShowExpenses()
Worksheets("Data").Select
End Sub

Sub ShowPurchases()
Worksheets("Segment").Select
End Sub

Sub ShowSales()
Worksheets("Facility").Select
End Sub

Sub RestoreExcelMenuBar()
CommandBars("Accounts").Delete
Application.Quit
End Sub


 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      10th Nov 2007
Are AddItem 1 and AddItem 2 entries in your combo box list, or do you have
two combo boxes with these names. Also, did you create the combo box(es)
from the Forms toolbar or the Control Toolbox toolbar?

"Kulin" wrote:

> Question :
> =======
> Exact syntax required when clicking/selecting AddItem 1 , I can invoke the
> following Sub ShowExpenses()
> Worksheets("Data").Select
> End Sub
>
>
> , on selecting AddItem 2, I can invoke the
>
> Sub ShowSales()
> Worksheets("Facility").Select
> End Sub
>
> and on selecting AddItem 3, I can invoke the following
>
> Sub ShowPurchases()
> Worksheets("Segment").Select
> End Sub
>
>
> Bye the way , I am little bit novice for VBA-EXCELL.
>
>
>
>
>
> My entire procedure start from here :
> ========================
>
>
>
> Sub CreateNewToolBar()
> 'the next two lines are only required during development
> On Error Resume Next
> CommandBars("Accounts").Delete
>
> Dim NewMenuBar As CommandBar
> Dim NewButton As CommandBarButton
>
> Set NewMenuBar = CommandBars.Add("Accounts")
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
> CommandBars("View").Controls("Normal").ID)
> NewButton.Caption = "&Normal"
> NewButton.Style = msoButtonIconAndCaptionBelow
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
> CommandBars("View").Controls("Page Break Preview").ID)
> NewButton.Caption = "&Preview"
> NewButton.Style = msoButtonIconAndCaption
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> NewButton.Caption = "&Data"
> NewButton.Style = msoButtonCaption
> NewButton.OnAction = "ShowExpenses"
>
> Dim NewComboboxButton As CommandBarComboBox
> Set NewComboboxButton = NewMenuBar.Controls.Add(msoControlComboBox)
> NewComboboxButton.Caption = "&Segment"
> NewComboboxButton.OnAction = "ShowPurchases"
> With CommandBars("Accounts").Controls(4)
> .AddItem "Item 1", 1
> .AddItem "Item 2", 2
> .AddItem "Item 3", 3
> .DropDownLines = 3
> .ListIndex = 1
> End With
>
>
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> NewButton.Caption = "&Facility"
> NewButton.Style = msoButtonCaption
> NewButton.OnAction = "ShowSales"
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> NewButton.Caption = "&E&xit"
> NewButton.OnAction = "RestoreExcelMenuBar"
> NewButton.Style = msoButtonCaption
>
> Worksheets("AccountsSheet").Select
> NewMenuBar.Visible = True
> End Sub
>
> Sub ShowExpenses()
> Worksheets("Data").Select
> End Sub
>
> Sub ShowPurchases()
> Worksheets("Segment").Select
> End Sub
>
> Sub ShowSales()
> Worksheets("Facility").Select
> End Sub
>
> Sub RestoreExcelMenuBar()
> CommandBars("Accounts").Delete
> Application.Quit
> End Sub
>
>

 
Reply With Quote
 
Tim Zych
Guest
Posts: n/a
 
      10th Nov 2007
I haven't replicated your environment...but this is the general idea.

In the creation of the combobox control, assign a Tag to it. The
OnAction/called macro ("ShowPurchases") evaluates whether the combo was
clicked. Then you figure out the value in the control and run whatever
action you need.

Add this to the part that creates the combobox control:
NewComboboxButton.Tag = "myCboButton"

Then in the "ShowPurchases" macro, add to your existing macro:

Select Case Application.CommandBars.ActionControl.Tag
Case "myCboButton"
Select Case
Application.CommandBars.FindControl(Tag:="myCboButton").Text
Case "Item 1"
' Do Whatever
Case "Item 2"
' Do something else
End Select
End Select



--
Tim Zych
SF, CA


"Kulin" <(E-Mail Removed)> wrote in message
news:E5C8C9EF-B145-448A-B3C1-(E-Mail Removed)...
> Question :
> =======
> Exact syntax required when clicking/selecting AddItem 1 , I can invoke the
> following Sub ShowExpenses()
> Worksheets("Data").Select
> End Sub
>
>
> , on selecting AddItem 2, I can invoke the
>
> Sub ShowSales()
> Worksheets("Facility").Select
> End Sub
>
> and on selecting AddItem 3, I can invoke the following
>
> Sub ShowPurchases()
> Worksheets("Segment").Select
> End Sub
>
>
> Bye the way , I am little bit novice for VBA-EXCELL.
>
>
>
>
>
> My entire procedure start from here :
> ========================
>
>
>
> Sub CreateNewToolBar()
> 'the next two lines are only required during development
> On Error Resume Next
> CommandBars("Accounts").Delete
>
> Dim NewMenuBar As CommandBar
> Dim NewButton As CommandBarButton
>
> Set NewMenuBar = CommandBars.Add("Accounts")
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
> CommandBars("View").Controls("Normal").ID)
> NewButton.Caption = "&Normal"
> NewButton.Style = msoButtonIconAndCaptionBelow
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
> CommandBars("View").Controls("Page Break Preview").ID)
> NewButton.Caption = "&Preview"
> NewButton.Style = msoButtonIconAndCaption
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> NewButton.Caption = "&Data"
> NewButton.Style = msoButtonCaption
> NewButton.OnAction = "ShowExpenses"
>
> Dim NewComboboxButton As CommandBarComboBox
> Set NewComboboxButton = NewMenuBar.Controls.Add(msoControlComboBox)
> NewComboboxButton.Caption = "&Segment"
> NewComboboxButton.OnAction = "ShowPurchases"
> With CommandBars("Accounts").Controls(4)
> .AddItem "Item 1", 1
> .AddItem "Item 2", 2
> .AddItem "Item 3", 3
> .DropDownLines = 3
> .ListIndex = 1
> End With
>
>
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> NewButton.Caption = "&Facility"
> NewButton.Style = msoButtonCaption
> NewButton.OnAction = "ShowSales"
>
> Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> NewButton.Caption = "&E&xit"
> NewButton.OnAction = "RestoreExcelMenuBar"
> NewButton.Style = msoButtonCaption
>
> Worksheets("AccountsSheet").Select
> NewMenuBar.Visible = True
> End Sub
>
> Sub ShowExpenses()
> Worksheets("Data").Select
> End Sub
>
> Sub ShowPurchases()
> Worksheets("Segment").Select
> End Sub
>
> Sub ShowSales()
> Worksheets("Facility").Select
> End Sub
>
> Sub RestoreExcelMenuBar()
> CommandBars("Accounts").Delete
> Application.Quit
> End Sub
>
>



 
Reply With Quote
 
=?Utf-8?B?S3VsaW4=?=
Guest
Posts: n/a
 
      11th Nov 2007
Thanks. I will try.

In the meantime, I did like this.

Sub ShowPurchases()
Dim sheetName as string
sheetName=Array(vbNullChar, "Data", "Facility",
"Segment")(CommandBars("Accounts").Controls(4).ListIndex)
Worksheets(sheetName).Select
End Sub


kulin

"Tim Zych" wrote:

> I haven't replicated your environment...but this is the general idea.
>
> In the creation of the combobox control, assign a Tag to it. The
> OnAction/called macro ("ShowPurchases") evaluates whether the combo was
> clicked. Then you figure out the value in the control and run whatever
> action you need.
>
> Add this to the part that creates the combobox control:
> NewComboboxButton.Tag = "myCboButton"
>
> Then in the "ShowPurchases" macro, add to your existing macro:
>
> Select Case Application.CommandBars.ActionControl.Tag
> Case "myCboButton"
> Select Case
> Application.CommandBars.FindControl(Tag:="myCboButton").Text
> Case "Item 1"
> ' Do Whatever
> Case "Item 2"
> ' Do something else
> End Select
> End Select
>
>
>
> --
> Tim Zych
> SF, CA
>
>
> "Kulin" <(E-Mail Removed)> wrote in message
> news:E5C8C9EF-B145-448A-B3C1-(E-Mail Removed)...
> > Question :
> > =======
> > Exact syntax required when clicking/selecting AddItem 1 , I can invoke the
> > following Sub ShowExpenses()
> > Worksheets("Data").Select
> > End Sub
> >
> >
> > , on selecting AddItem 2, I can invoke the
> >
> > Sub ShowSales()
> > Worksheets("Facility").Select
> > End Sub
> >
> > and on selecting AddItem 3, I can invoke the following
> >
> > Sub ShowPurchases()
> > Worksheets("Segment").Select
> > End Sub
> >
> >
> > Bye the way , I am little bit novice for VBA-EXCELL.
> >
> >
> >
> >
> >
> > My entire procedure start from here :
> > ========================
> >
> >
> >
> > Sub CreateNewToolBar()
> > 'the next two lines are only required during development
> > On Error Resume Next
> > CommandBars("Accounts").Delete
> >
> > Dim NewMenuBar As CommandBar
> > Dim NewButton As CommandBarButton
> >
> > Set NewMenuBar = CommandBars.Add("Accounts")
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
> > CommandBars("View").Controls("Normal").ID)
> > NewButton.Caption = "&Normal"
> > NewButton.Style = msoButtonIconAndCaptionBelow
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
> > CommandBars("View").Controls("Page Break Preview").ID)
> > NewButton.Caption = "&Preview"
> > NewButton.Style = msoButtonIconAndCaption
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> > NewButton.Caption = "&Data"
> > NewButton.Style = msoButtonCaption
> > NewButton.OnAction = "ShowExpenses"
> >
> > Dim NewComboboxButton As CommandBarComboBox
> > Set NewComboboxButton = NewMenuBar.Controls.Add(msoControlComboBox)
> > NewComboboxButton.Caption = "&Segment"
> > NewComboboxButton.OnAction = "ShowPurchases"
> > With CommandBars("Accounts").Controls(4)
> > .AddItem "Item 1", 1
> > .AddItem "Item 2", 2
> > .AddItem "Item 3", 3
> > .DropDownLines = 3
> > .ListIndex = 1
> > End With
> >
> >
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> > NewButton.Caption = "&Facility"
> > NewButton.Style = msoButtonCaption
> > NewButton.OnAction = "ShowSales"
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> > NewButton.Caption = "&E&xit"
> > NewButton.OnAction = "RestoreExcelMenuBar"
> > NewButton.Style = msoButtonCaption
> >
> > Worksheets("AccountsSheet").Select
> > NewMenuBar.Visible = True
> > End Sub
> >
> > Sub ShowExpenses()
> > Worksheets("Data").Select
> > End Sub
> >
> > Sub ShowPurchases()
> > Worksheets("Segment").Select
> > End Sub
> >
> > Sub ShowSales()
> > Worksheets("Facility").Select
> > End Sub
> >
> > Sub RestoreExcelMenuBar()
> > CommandBars("Accounts").Delete
> > Application.Quit
> > End Sub
> >
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?S3VsaW4=?=
Guest
Posts: n/a
 
      11th Nov 2007
Thanks. I did like this:

Sub ShowPurchases()
Dim sheetName as string
sheetName=Array(vbNullChar, "Data", "Facility",
"Segment")(CommandBars("Accounts").Controls(4).ListIndex)
Worksheets(sheetName).Select
End Sub

kulin


"JLGWhiz" wrote:

> Are AddItem 1 and AddItem 2 entries in your combo box list, or do you have
> two combo boxes with these names. Also, did you create the combo box(es)
> from the Forms toolbar or the Control Toolbox toolbar?
>
> "Kulin" wrote:
>
> > Question :
> > =======
> > Exact syntax required when clicking/selecting AddItem 1 , I can invoke the
> > following Sub ShowExpenses()
> > Worksheets("Data").Select
> > End Sub
> >
> >
> > , on selecting AddItem 2, I can invoke the
> >
> > Sub ShowSales()
> > Worksheets("Facility").Select
> > End Sub
> >
> > and on selecting AddItem 3, I can invoke the following
> >
> > Sub ShowPurchases()
> > Worksheets("Segment").Select
> > End Sub
> >
> >
> > Bye the way , I am little bit novice for VBA-EXCELL.
> >
> >
> >
> >
> >
> > My entire procedure start from here :
> > ========================
> >
> >
> >
> > Sub CreateNewToolBar()
> > 'the next two lines are only required during development
> > On Error Resume Next
> > CommandBars("Accounts").Delete
> >
> > Dim NewMenuBar As CommandBar
> > Dim NewButton As CommandBarButton
> >
> > Set NewMenuBar = CommandBars.Add("Accounts")
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
> > CommandBars("View").Controls("Normal").ID)
> > NewButton.Caption = "&Normal"
> > NewButton.Style = msoButtonIconAndCaptionBelow
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton,
> > CommandBars("View").Controls("Page Break Preview").ID)
> > NewButton.Caption = "&Preview"
> > NewButton.Style = msoButtonIconAndCaption
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> > NewButton.Caption = "&Data"
> > NewButton.Style = msoButtonCaption
> > NewButton.OnAction = "ShowExpenses"
> >
> > Dim NewComboboxButton As CommandBarComboBox
> > Set NewComboboxButton = NewMenuBar.Controls.Add(msoControlComboBox)
> > NewComboboxButton.Caption = "&Segment"
> > NewComboboxButton.OnAction = "ShowPurchases"
> > With CommandBars("Accounts").Controls(4)
> > .AddItem "Item 1", 1
> > .AddItem "Item 2", 2
> > .AddItem "Item 3", 3
> > .DropDownLines = 3
> > .ListIndex = 1
> > End With
> >
> >
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> > NewButton.Caption = "&Facility"
> > NewButton.Style = msoButtonCaption
> > NewButton.OnAction = "ShowSales"
> >
> > Set NewButton = NewMenuBar.Controls.Add(msoControlButton)
> > NewButton.Caption = "&E&xit"
> > NewButton.OnAction = "RestoreExcelMenuBar"
> > NewButton.Style = msoButtonCaption
> >
> > Worksheets("AccountsSheet").Select
> > NewMenuBar.Visible = True
> > End Sub
> >
> > Sub ShowExpenses()
> > Worksheets("Data").Select
> > End Sub
> >
> > Sub ShowPurchases()
> > Worksheets("Segment").Select
> > End Sub
> >
> > Sub ShowSales()
> > Worksheets("Facility").Select
> > End Sub
> >
> > Sub RestoreExcelMenuBar()
> > CommandBars("Accounts").Delete
> > Application.Quit
> > End Sub
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimize Store Procedure routine inadsad@hotmail.com Microsoft VB .NET 1 18th Apr 2008 04:02 PM
VBA routine in detail on print routine causing errors in report Jeff Wimer Microsoft Access Reports 0 21st Oct 2005 01:54 AM
CommandBarComboBox Camus SoNiCo Microsoft Outlook Program Addins 0 14th Oct 2005 06:54 PM
CommandBarComboBox.AddItem - String Length Limit? =?Utf-8?B?WWlzaGk=?= Microsoft Excel Programming 0 20th Jan 2004 07:21 PM
how to pass a return value from a sql 2000 stored procedure into access vba routine Keith G Hicks Microsoft Access ADP SQL Server 10 1st Oct 2003 03:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:03 PM.