Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Resetting Activex comboboxes to blank

I've searched posts thoroughly, and I believe I've got the syntax
right, but it won't work.
'xxxxxxxxxxxxxxxxxxxxx
Private Sub CommandButton1_Click()

Dim oleObj As OLEObject
Dim x As Long
Dim myCmbo As String

On Error GoTo Rats

Application.EnableEvents = True

x = 1
For Each oleObj In ActiveSheet.OLEObjects
myCmbo = "Combobox" & x
If oleObj.Name = myCmbo Then '<---skips right to end-if
oleObj.ListIndex = -1
x = x + 1
End If
Next oleObj

Application.EnableEvents = False

ActiveSheet.Range("h:h").ClearContents
ActiveSheet.Range("h1").Formula = "=sum(H5:H65)"

Application.EnableEvents = True

Exit Sub

'++++++++++++++++++++++++++++
Rats:
MsgBox "Error"
Application.EnableEvents = True
Exit Sub
'++++++++++++++++++++++++++++

End Sub
'xxxxxxxxxxxxxxxxxxxxxxxxxxxx

even when the Intellisense says that oleObj.Name = myCmbo (the If
test), it skips right over what I want it to do & goes right to "End
If". arrrrg! I can't even test to see if .....oleObj.ListIndex =
-1...... will do what I want because I can't get it to trigger. what
am I doing wrong?? at first I thought it was because I had
Application.EnableEvents = False (because I've got a sheet_calculate
sub that was triggering), but I deliberately turned it back on & it
still won't catch. any ideas?
thanks
Susan



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Resetting Activex comboboxes to blank

Did you want to reset all the comboboxes on the worksheet?

If yes:

Option Explicit
Private Sub CommandButton1_Click()

Dim OLEObj As OLEObject

For Each OLEObj In Me.OLEObjects
If TypeOf OLEObj.Object Is MSForms.ComboBox Then
OLEObj.Object.ListIndex = -1
End If
Next OLEObj

Application.EnableEvents = False
Me.Range("h:h").ClearContents
Me.Range("h1").Formula = "=sum(H5:H65)"
Application.EnableEvents = True

End Sub

Me is a keyword that represents the object that owns the code. In this case the
worksheet with the button and comboboxes.



Susan wrote:

I've searched posts thoroughly, and I believe I've got the syntax
right, but it won't work.
'xxxxxxxxxxxxxxxxxxxxx
Private Sub CommandButton1_Click()

Dim oleObj As OLEObject
Dim x As Long
Dim myCmbo As String

On Error GoTo Rats

Application.EnableEvents = True

x = 1
For Each oleObj In ActiveSheet.OLEObjects
myCmbo = "Combobox" & x
If oleObj.Name = myCmbo Then '<---skips right to end-if
oleObj.ListIndex = -1
x = x + 1
End If
Next oleObj

Application.EnableEvents = False

ActiveSheet.Range("h:h").ClearContents
ActiveSheet.Range("h1").Formula = "=sum(H5:H65)"

Application.EnableEvents = True

Exit Sub

'++++++++++++++++++++++++++++
Rats:
MsgBox "Error"
Application.EnableEvents = True
Exit Sub
'++++++++++++++++++++++++++++

End Sub
'xxxxxxxxxxxxxxxxxxxxxxxxxxxx

even when the Intellisense says that oleObj.Name = myCmbo (the If
test), it skips right over what I want it to do & goes right to "End
If". arrrrg! I can't even test to see if .....oleObj.ListIndex =
-1...... will do what I want because I can't get it to trigger. what
am I doing wrong?? at first I thought it was because I had
Application.EnableEvents = False (because I've got a sheet_calculate
sub that was triggering), but I deliberately turned it back on & it
still won't catch. any ideas?
thanks
Susan


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Resetting Activex comboboxes to blank

yes!!!!!!! hurrah!
thank you!
it was the "me" keyword that i was lacking, because i had tried that
exact coding (and i was missing the addition of .object) except i was
using activesheet.oleobjects.
thanks a lot, it works perfectly.
susan


On Oct 14, 3:30*pm, Dave Peterson wrote:
Did you want to reset all the comboboxes on the worksheet?

If yes:

Option Explicit
Private Sub CommandButton1_Click()

* * Dim OLEObj As OLEObject

* * For Each OLEObj In Me.OLEObjects
* * * * If TypeOf OLEObj.Object Is MSForms.ComboBox Then
* * * * * * OLEObj.Object.ListIndex = -1
* * * * End If
* * Next OLEObj

* * Application.EnableEvents = False
* * Me.Range("h:h").ClearContents
* * Me.Range("h1").Formula = "=sum(H5:H65)"
* * Application.EnableEvents = True

End Sub

Me is a keyword that represents the object that owns the code. *In this case the
worksheet with the button and comboboxes.





Susan wrote:

I've searched posts thoroughly, and I believe I've got the syntax
right, but it won't work.
'xxxxxxxxxxxxxxxxxxxxx
Private Sub CommandButton1_Click()


Dim oleObj As OLEObject
Dim x As Long
Dim myCmbo As String


On Error GoTo Rats


Application.EnableEvents = True


x = 1
For Each oleObj In ActiveSheet.OLEObjects
* *myCmbo = "Combobox" & x
* *If oleObj.Name = myCmbo Then *'<---skips right to end-if
* * * oleObj.ListIndex = -1
* * * x = x + 1
* *End If
Next oleObj


Application.EnableEvents = False


ActiveSheet.Range("h:h").ClearContents
ActiveSheet.Range("h1").Formula = "=sum(H5:H65)"


Application.EnableEvents = True


Exit Sub


'++++++++++++++++++++++++++++
Rats:
MsgBox "Error"
Application.EnableEvents = True
Exit Sub
'++++++++++++++++++++++++++++


End Sub
'xxxxxxxxxxxxxxxxxxxxxxxxxxxx


even when the Intellisense says that oleObj.Name = myCmbo (the If
test), it skips right over what I want it to do & goes right to "End
If". *arrrrg! *I can't even test to see if .....oleObj.ListIndex =
-1...... will do what I want because I can't get it to trigger. *what
am I doing wrong?? *at first I thought it was because I had
Application.EnableEvents = False (because I've got a sheet_calculate
sub that was triggering), but I deliberately turned it back on & it
still won't catch. *any ideas?
thanks
Susan


--

Dave Peterson- Hide quoted text -

- Show quoted text -


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
Not resetting all cells Chuck Excel Programming 7 December 18th 07 03:07 AM
publish activeX combobox and other activeX control irene c Excel Programming 0 March 19th 07 07:19 AM
ActiveX comboboxes on worksheet (lost focus problems) [email protected] Excel Programming 5 February 13th 07 03:51 PM
Dir function resetting Emily Edgington Excel Programming 7 April 4th 05 09:41 PM
Used Range is not resetting R Avery Excel Programming 8 May 28th 04 11:31 AM


All times are GMT +1. The time now is 08:54 AM.

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

About Us

"It's about Microsoft Excel"