LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default How to Pass a Form to a Function - 2007

Hi,
Is there a way to pass a form to a function in VBA. For example, I have
created several userforms all of which have a combobox that I want filled
using the same set of code. Instead of including this code in each of the
forms code, I want to make this a function in a module and have the form just
call the function to fill the combobox. The function would accept the form
name or whatever and use it to fill the combobox.
I am new to VBA and have tried using
Public Function FillSize(Obj As MSForms.UserForm)
For i = 1 To Obj.cmdSize.ListCount
'Removes an item from the Combo Box
Obj.cmdSize.RemoveItem 0
Next i

With Obj.cmdSize
.AddItem "AddStuff" 'Add to combo box by reading excel sheet

End With
End Function

And I would call the function using
FillSize(Me)
OR
FillSize(UserForm_Name)

Unfortunately I am not the most experienced of programmers and I am unsure
how to accomplish this, if my code is even a step in the right direction, or
even if it possible to accomplish what Im asking.

Thanks for any help in advance,
--
Aaron
 
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
Pass variable from form to form to form headly Excel Programming 1 May 31st 06 02:50 AM
Pass a form Listbox as an object Brian Excel Programming 2 November 18th 05 11:51 PM
Pass string value to another form yangyh[_5_] Excel Programming 1 September 11th 05 10:01 AM
Is it possible to open the VBA form with a link in a sheet and to pass variable from a cell to the VBA form? Daniel[_14_] Excel Programming 1 August 29th 04 01:20 PM
Pass parameter to a form and then open it? Darren Hill[_2_] Excel Programming 3 February 7th 04 06:21 PM


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