Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Setting a VBA Control as a variable

I have tried to get a VBA control located on a sheet set into a variable. I
first declare a variable as a listbox, then try to set it as a listbox. It
throws an error at that point. I want to save mysel a lot of coding by
coverting repetitive procedures into methods, btu this is throwing a monkey
wrench into things. Thanks for any help.

Here is a snipet of code of what I'm trying to do:


Private Sub cmdPull_Click()
'VAR
Dim lboPullType As ListBox

'BEGIN
'Initialize Listbox
Set lboPullType = Me.OLEObjects("lboWBSID")

'get Departments listed in Listbox
GetChosenDept arDept(), lboPullType

End Sub

Sub GetChosenDept(ByRef Dept() As String, LBox As OLEObject)

'VAR
Dim inx As Integer
Dim iCount As Integer
Dim bDeptLimited As Boolean
Dim sDept As String

'BEGIN

'For each item in the Listbox
For inx = 0 To LBox.ListCount - 1
'If item is selected, add to array
If LBox.Selected(inx) Then
iCount = iCount + 1
ReDim Preserve Dept(iCount)
Dept(iCount) = LBox.List(inx)
End If
Next
If at least one department was chosen, set bool
If iCount 0 Then
bDeptLimited = True
Else
bDeptLimited = False
End If
'Are we pulling a Heirarchy?
If Me.cboDeptHierarchy And bDeptLimited Then
For inx = 1 To UBound(arDept)
sDept = Dept(inx)
Next
Erase Dept()
'Get all departments under this one.
GetSubDepts sDept, Dept()
End If


End Sub

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Setting a VBA Control as a variable

Have you tried declaring the list box as
MSForms.ListBox?


"J Streger" wrote:

I have tried to get a VBA control located on a sheet set into a variable. I
first declare a variable as a listbox, then try to set it as a listbox. It
throws an error at that point. I want to save mysel a lot of coding by
coverting repetitive procedures into methods, btu this is throwing a monkey
wrench into things. Thanks for any help.

Here is a snipet of code of what I'm trying to do:


Private Sub cmdPull_Click()
'VAR
Dim lboPullType As ListBox

'BEGIN
'Initialize Listbox
Set lboPullType = Me.OLEObjects("lboWBSID")

'get Departments listed in Listbox
GetChosenDept arDept(), lboPullType

End Sub

Sub GetChosenDept(ByRef Dept() As String, LBox As OLEObject)

'VAR
Dim inx As Integer
Dim iCount As Integer
Dim bDeptLimited As Boolean
Dim sDept As String

'BEGIN

'For each item in the Listbox
For inx = 0 To LBox.ListCount - 1
'If item is selected, add to array
If LBox.Selected(inx) Then
iCount = iCount + 1
ReDim Preserve Dept(iCount)
Dept(iCount) = LBox.List(inx)
End If
Next
If at least one department was chosen, set bool
If iCount 0 Then
bDeptLimited = True
Else
bDeptLimited = False
End If
'Are we pulling a Heirarchy?
If Me.cboDeptHierarchy And bDeptLimited Then
For inx = 1 To UBound(arDept)
sDept = Dept(inx)
Next
Erase Dept()
'Get all departments under this one.
GetSubDepts sDept, Dept()
End If


End Sub

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Setting a VBA Control as a variable

Thank you very much. That did it!

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003



"Alok" wrote:

Have you tried declaring the list box as
MSForms.ListBox?


"J Streger" wrote:

I have tried to get a VBA control located on a sheet set into a variable. I
first declare a variable as a listbox, then try to set it as a listbox. It
throws an error at that point. I want to save mysel a lot of coding by
coverting repetitive procedures into methods, btu this is throwing a monkey
wrench into things. Thanks for any help.

Here is a snipet of code of what I'm trying to do:


Private Sub cmdPull_Click()
'VAR
Dim lboPullType As ListBox

'BEGIN
'Initialize Listbox
Set lboPullType = Me.OLEObjects("lboWBSID")

'get Departments listed in Listbox
GetChosenDept arDept(), lboPullType

End Sub

Sub GetChosenDept(ByRef Dept() As String, LBox As OLEObject)

'VAR
Dim inx As Integer
Dim iCount As Integer
Dim bDeptLimited As Boolean
Dim sDept As String

'BEGIN

'For each item in the Listbox
For inx = 0 To LBox.ListCount - 1
'If item is selected, add to array
If LBox.Selected(inx) Then
iCount = iCount + 1
ReDim Preserve Dept(iCount)
Dept(iCount) = LBox.List(inx)
End If
Next
If at least one department was chosen, set bool
If iCount 0 Then
bDeptLimited = True
Else
bDeptLimited = False
End If
'Are we pulling a Heirarchy?
If Me.cboDeptHierarchy And bDeptLimited Then
For inx = 1 To UBound(arDept)
sDept = Dept(inx)
Next
Erase Dept()
'Get all departments under this one.
GetSubDepts sDept, Dept()
End If


End Sub

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

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
Setting Control End Limit Earl Excel Discussion (Misc queries) 1 April 20th 06 08:28 PM
Setting an option control Patrick Simonds Excel Programming 1 April 4th 06 03:25 AM
setting ComboBox Control font ts1 Excel Programming 0 September 22nd 05 06:35 PM
Setting LinkedCell on a CheckBox Control scottrell Excel Programming 2 July 30th 04 11:06 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM


All times are GMT +1. The time now is 10: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"