Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default how to remove selected sheet from CommandBarComboBox

i have a code which adds sheet names to combo box

Dim ctrl As CommandBarControl
Dim wks

Set ctrl = Application.CommandBars("myNavigator") _
.FindControl(Tag:="__wksnames__")
ctrl.Clear

For Each wks In ActiveWorkbook.Sheets
'If wks.Visible = xlSheetVisible Then
ctrl.AddItem wks.Name
'End If
Next wks
End Sub

i need a code which deletes the selected sheet from combo box... the
following code is throwing me an error .........

Set ctrl = .Controls.Add(Type:=msoControlButton, temporary:=True)
With ctrl
.Style = msoButtonCaption
.Caption = "Delete Sheets"
.OnAction = "'" & ThisWorkbook.Name & "'!DeleteSheets"
End With
End With

Sub DeleteSheets()
Dim myWksName As String
Dim wks

With Application.CommandBars.ActionControl
If .ListIndex = 0 Then
MsgBox "Please select an existing sheet"
Exit Sub
Else

.Delete .List(.ListIndex)
End If
End With

Set wks = Nothing
On Error Resume Next
On Error GoTo 0

If wks Is Nothing Then
Call RefreshTheSheets
MsgBox "Please try again"
Else
wks.Select
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default how to remove selected sheet from CommandBarComboBox

With the snippets of code you posted it's difficult to know what you have
and what you want to do. Your Button is assigned to 'DeleteSheets' in which
you have

With Application.CommandBars.ActionControl
If .ListIndex = 0 Then

So is that a button or a combo

Guessing at what you have, and I could be completely wrong, you've got a
button and a combo, the combo holds a list of sheet names, user presses the
button to delete the sheet selected in the combo. Maybe you want something
like


Sub DeleteSheets()
Dim myWksName As String

Set ctrl = Application.CommandBars("myNavigator") _
.FindControl(Tag:="__wksnames__") ' the combo

' If ctrl.ListIndex = 0 Then
' MsgBox "Please select an existing sheet"
' Exit Sub
' end if
with ctrl
' first get confirmation from user
' error handling etc
Application.DisplayAlerts = False
myWksName = .Text
Worksheets(myWksName).Delete
Application.DisplayAlerts = True

.RemoveItem (.ListIndex)

End With


Regards,
Peter T

"vicky" wrote in message
...
i have a code which adds sheet names to combo box

Dim ctrl As CommandBarControl
Dim wks

Set ctrl = Application.CommandBars("myNavigator") _
.FindControl(Tag:="__wksnames__")
ctrl.Clear

For Each wks In ActiveWorkbook.Sheets
'If wks.Visible = xlSheetVisible Then
ctrl.AddItem wks.Name
'End If
Next wks
End Sub

i need a code which deletes the selected sheet from combo box... the
following code is throwing me an error .........

Set ctrl = .Controls.Add(Type:=msoControlButton, temporary:=True)
With ctrl
.Style = msoButtonCaption
.Caption = "Delete Sheets"
.OnAction = "'" & ThisWorkbook.Name & "'!DeleteSheets"
End With
End With

Sub DeleteSheets()
Dim myWksName As String
Dim wks

With Application.CommandBars.ActionControl
If .ListIndex = 0 Then
MsgBox "Please select an existing sheet"
Exit Sub
Else

.Delete .List(.ListIndex)
End If
End With

Set wks = Nothing
On Error Resume Next
On Error GoTo 0

If wks Is Nothing Then
Call RefreshTheSheets
MsgBox "Please try again"
Else
wks.Select
End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default how to remove selected sheet from CommandBarComboBox

Untested...

Sub DeleteSheets()
Dim myWksName As String
Dim wks

With Application.CommandBars.ActionControl
If .ListIndex = 0 Then
MsgBox "Please select an existing sheet"
Exit Sub
Else

application.enableevents = false 'no warning message
on error resume next
activeworkbook.worksheets(.List(.ListIndex)).delet e
if err.number < 0 then
err.clear
msgbox "delete failed"
end if
application.enableevents = true
End With

'do clean up the list yourself--let this sub do the work
Call RefreshTheSheets

End Sub

vicky wrote:

i have a code which adds sheet names to combo box

Dim ctrl As CommandBarControl
Dim wks

Set ctrl = Application.CommandBars("myNavigator") _
.FindControl(Tag:="__wksnames__")
ctrl.Clear

For Each wks In ActiveWorkbook.Sheets
'If wks.Visible = xlSheetVisible Then
ctrl.AddItem wks.Name
'End If
Next wks
End Sub

i need a code which deletes the selected sheet from combo box... the
following code is throwing me an error .........

Set ctrl = .Controls.Add(Type:=msoControlButton, temporary:=True)
With ctrl
.Style = msoButtonCaption
.Caption = "Delete Sheets"
.OnAction = "'" & ThisWorkbook.Name & "'!DeleteSheets"
End With
End With

Sub DeleteSheets()
Dim myWksName As String
Dim wks

With Application.CommandBars.ActionControl
If .ListIndex = 0 Then
MsgBox "Please select an existing sheet"
Exit Sub
Else

.Delete .List(.ListIndex)
End If
End With

Set wks = Nothing
On Error Resume Next
On Error GoTo 0

If wks Is Nothing Then
Call RefreshTheSheets
MsgBox "Please try again"
Else
wks.Select
End If

End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default how to remove selected sheet from CommandBarComboBox

I think you want to use the RemoveItem method. Here is a snippet from the
VBA help file that might help.

Private Sub CommandButton2_Click()
'Ensure ListBox contains list items
If ListBox1.ListCount = 1 Then
'If no selection, choose last list item.
If ListBox1.ListIndex = -1 Then
ListBox1.ListIndex = _
ListBox1.ListCount - 1
End If
ListBox1.RemoveItem (ListBox1.ListIndex)
End If
End Sub



"vicky" wrote in message
...
i have a code which adds sheet names to combo box

Dim ctrl As CommandBarControl
Dim wks

Set ctrl = Application.CommandBars("myNavigator") _
.FindControl(Tag:="__wksnames__")
ctrl.Clear

For Each wks In ActiveWorkbook.Sheets
'If wks.Visible = xlSheetVisible Then
ctrl.AddItem wks.Name
'End If
Next wks
End Sub

i need a code which deletes the selected sheet from combo box... the
following code is throwing me an error .........

Set ctrl = .Controls.Add(Type:=msoControlButton, temporary:=True)
With ctrl
.Style = msoButtonCaption
.Caption = "Delete Sheets"
.OnAction = "'" & ThisWorkbook.Name & "'!DeleteSheets"
End With
End With

Sub DeleteSheets()
Dim myWksName As String
Dim wks

With Application.CommandBars.ActionControl
If .ListIndex = 0 Then
MsgBox "Please select an existing sheet"
Exit Sub
Else

.Delete .List(.ListIndex)
End If
End With

Set wks = Nothing
On Error Resume Next
On Error GoTo 0

If wks Is Nothing Then
Call RefreshTheSheets
MsgBox "Please try again"
Else
wks.Select
End If

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
CommandBarComboBox : AddItem - procedure to attach routine. Kulin Excel Programming 4 November 11th 07 04:06 AM
commandbarCombobox problem MVM Excel Programming 7 January 27th 06 05:12 PM
how do i make it so that when a sheat is selected either via link or tab, that xlLastCell is selected. the last on the sheet. Daniel Excel Worksheet Functions 1 July 12th 05 01:30 AM
Remove .xls from selected files Zurn Excel Programming 3 September 24th 04 02:06 PM
CommandBarComboBox.AddItem - String Length Limit? Yishi Excel Programming 0 January 20th 04 07:21 PM


All times are GMT +1. The time now is 07:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"