O
OssieMac
I actually posted this in a previous thread about a different issue that Dave
Peterson answered but because it is really an entirely different question I
thought it might be advisable to re-post in a separate thread.
Refer to my code example below with comments.
I create a list box on a worksheet using code but I am unable to then select
any of the items in the list box unless I manually turn Design Mode On then
Off again.
Therefore I thought that a work around would be to turn Design Mode On then
Off again with code. However, I can turn it On with code but have not been
successful in turning it Off.
I will very much appeciate any help I can get to overcome this problem.
Private Sub CommandButton2_Click()
Dim lListBox As Double
Dim tListBox As Double
Dim hListBox As Double
Dim wListBox As Double
Dim lstBox As OLEObject
Dim i As Long
With Me
lListBox = .Cells(2, 2).Left
tListBox = .Cells(2, 2).Top
wListBox = 100
hListBox = 150
Set lstBox = .OLEObjects.Add _
(ClassType:="Forms.ListBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=lListBox, _
Top:=tListBox, _
Width:=wListBox, _
Height:=hListBox)
With lstBox.Object
For i = 1 To 10
.AddItem "Test" & i
Next i
.MultiSelect = fmMultiSelectMulti
End With
End With
Set lstBox = Nothing
'**********************************
'Tested the following code with minimal success
'Following line turns Design Mode ON in xl2007
Application.CommandBars.ExecuteMso ("DesignMode")
'Following line turns Design Mode ON in xl2002
'(Also works in xl2007)
'Application.CommandBars.FindControl(ID:=1605).Execute
'Following lines turn Design Mode OFF in xl2002
'but will only work if run in a separate sub
'after this sub has finished.
'With CommandBars("Exit Design Mode").Controls(1)
' If .State = msoButtonDown Then .Execute
'End With
'*************************************
End Sub
Peterson answered but because it is really an entirely different question I
thought it might be advisable to re-post in a separate thread.
Refer to my code example below with comments.
I create a list box on a worksheet using code but I am unable to then select
any of the items in the list box unless I manually turn Design Mode On then
Off again.
Therefore I thought that a work around would be to turn Design Mode On then
Off again with code. However, I can turn it On with code but have not been
successful in turning it Off.
I will very much appeciate any help I can get to overcome this problem.
Private Sub CommandButton2_Click()
Dim lListBox As Double
Dim tListBox As Double
Dim hListBox As Double
Dim wListBox As Double
Dim lstBox As OLEObject
Dim i As Long
With Me
lListBox = .Cells(2, 2).Left
tListBox = .Cells(2, 2).Top
wListBox = 100
hListBox = 150
Set lstBox = .OLEObjects.Add _
(ClassType:="Forms.ListBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=lListBox, _
Top:=tListBox, _
Width:=wListBox, _
Height:=hListBox)
With lstBox.Object
For i = 1 To 10
.AddItem "Test" & i
Next i
.MultiSelect = fmMultiSelectMulti
End With
End With
Set lstBox = Nothing
'**********************************
'Tested the following code with minimal success
'Following line turns Design Mode ON in xl2007
Application.CommandBars.ExecuteMso ("DesignMode")
'Following line turns Design Mode ON in xl2002
'(Also works in xl2007)
'Application.CommandBars.FindControl(ID:=1605).Execute
'Following lines turn Design Mode OFF in xl2002
'but will only work if run in a separate sub
'after this sub has finished.
'With CommandBars("Exit Design Mode").Controls(1)
' If .State = msoButtonDown Then .Execute
'End With
'*************************************
End Sub