<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Passing Arguments to a Userform</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Wed, 08 Feb 2012 23:58:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Bhavik</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-51472</link>
		<dc:creator>Bhavik</dc:creator>
		<pubDate>Wed, 29 Sep 2010 01:04:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-51472</guid>
		<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;i am completely new to VB. with some help i have created a userform with some command buttons on it &amp; i have also inserted a Combobox with drop down option from the same worksheet but different workbook.the dropdowm options are basically states of the US. &lt;/p&gt;
&lt;p&gt;now i want to input an excel in the userform, that should populate data from a worksheet in the same workbook.&lt;/p&gt;
&lt;p&gt;based on the state selection in the dropdown of the combobox, in the excel sheet i need to populate the data related to that particular state from column A to Column BI&lt;/p&gt;
&lt;p&gt;i am not able to get an excel sheet in the user form, and please let me know how do i get it related to the dropdown option.&lt;/p&gt;
&lt;p&gt;Any help would be greatly appreciated. &lt;/p&gt;
&lt;p&gt;Thanks in advance.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>i am completely new to VB. with some help i have created a userform with some command buttons on it &amp; i have also inserted a Combobox with drop down option from the same worksheet but different workbook.the dropdowm options are basically states of the US. </p>
<p>now i want to input an excel in the userform, that should populate data from a worksheet in the same workbook.</p>
<p>based on the state selection in the dropdown of the combobox, in the excel sheet i need to populate the data related to that particular state from column A to Column BI</p>
<p>i am not able to get an excel sheet in the user form, and please let me know how do i get it related to the dropdown option.</p>
<p>Any help would be greatly appreciated. </p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tushar Mehta</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-42038</link>
		<dc:creator>Tushar Mehta</dc:creator>
		<pubDate>Wed, 11 Nov 2009 20:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-42038</guid>
		<description>&lt;p&gt;Marty: For a different take on the subject see&lt;br&gt;
Userform Interface Design&lt;br&gt;
&lt;a href=&quot;http://www.tushar-mehta.com/publish_train/book_vba/09_userinterface.htm&quot; rel=&quot;nofollow&quot;&gt;http://www.tushar-mehta.com/publish_train/book_vba/09_userinterface.htm&lt;/a&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Marty: For a different take on the subject see<br />
Userform Interface Design<br />
<a href="http://www.tushar-mehta.com/publish_train/book_vba/09_userinterface.htm" rel="nofollow">http://www.tushar-mehta.com/publish_train/book_vba/09_userinterface.htm</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marty Ratcliff</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-42034</link>
		<dc:creator>Marty Ratcliff</dc:creator>
		<pubDate>Wed, 11 Nov 2009 16:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-42034</guid>
		<description>&lt;p&gt;Erik Eckhardt&#039;s succinct example (March 3, 2006) of passing multiple parameters to a form via form properties was exactly what I was looking for when nothing else seemed to explain the sequence of events that take place during communication between sub and form module&#039;s &quot;properties&quot; and the form itself.&lt;/p&gt;
&lt;p&gt;After setting up his example, I followed breakpoints throughout execution of the program and plotted 12 steps that occur starting with the &quot;Set F = New frmValuePass&quot; and ending with &quot;Set F = Nothing&quot; and suddenly the light came on.  I sketched it out on paper and then applied same structure to my own code &amp; form and within an hour had accomplished what I&#039;d struggled with for about 2 days.&lt;/p&gt;
&lt;p&gt;My problem seemed to be figuring out how to load up a listbox of a form prior to showing the form but where the listbox&#039;s &quot;AddItem&quot; logic needed some passed arguments from my main sub in order to know what to add to the listbox, and needed other passed arguments to be merely displayed on the form once shown (text box, labels, etc.).  I kept trying to figure out how to use a form&#039;s &quot;initialize&quot; routine to invoke the ListBox logic, which was of course way too soon IF one needs to 1st pass several arguments to the form&#039;s environment.&lt;/p&gt;
&lt;p&gt;Just in case someone else reading thru this is struggling as I was with the issue of passing multiple arguments to a form via properties (the &quot;recommended&quot; method) prior to the form&#039;s execution, I&#039;ll try to enunciate the key points that were eluding me, a 1st-time form-with- listbox user (some of this is spelled out in Erik&#039;s self-documented code):&lt;/p&gt;
&lt;p&gt;[This will all make much more sense if you code up Erik&#039;s example -- including every single one of his embedded comments -- and then set breakpoints at everything in the controlling sub and everything in the form&#039;s property routines and subs and then monitor the code as it executes.  You can read his comments during breakpoint pauses and make your own notes and likely not even bother with anything else I have to say below.]&lt;/p&gt;
&lt;p&gt;1) It helped when I categorized the &quot;sequential events&quot; in 3 visual columns:&lt;br&gt;
  a) Sub events (controlling sub)&lt;br&gt;
  b) Form Properties &amp; Form Sub events&lt;br&gt;
  c) Form itself&lt;br&gt;
   The &quot;sequential events&quot; will zig-zag from column-to-column during execution&lt;/p&gt;
&lt;p&gt;2) The form doesn&#039;t really require an &quot;initialize&quot; routine prior to passing it some property values.  As Erik pointed out, mere instantiation is enough in the sub&#039;s &quot;Set F = New frmValuePass&quot; statement.  Turns out I didn&#039;t need to execute &quot;ListBox AddItem&quot; logic until immediately prior to the &quot;Show&quot; command.&lt;/p&gt;
&lt;p&gt;3) The sub&#039;s invoking of a specific property&#039;s &quot;Let&quot; routine in the form module will regain control of events immediately after the &quot;Let&quot; routine is executed.  i.e., the controlling sub&#039;s &quot;F.Value1 = 8? invokes the corresponding &quot;Let&quot; routine in the form module at which point control returns to the sub.  And realize that this can be done repeatedly as many times as needed by the controlling sub (hence multiple arguments passed to the form).&lt;/p&gt;
&lt;p&gt;4) Realization that by using the &quot;Let&quot; properties to &quot;hold&quot; the passed argument in a separately-named argument, the named argument (and not the property name itself) is where the passed argument will be made available later down the road in your form&#039;s logic WITHOUT a requirement to use a GET routine.  i.e., &quot;gValue1 = TheValue&quot; in Erik&#039;s &quot;Let Value1? routine stages the passed argument in &quot;gValue1? which demonstrates &#039;persistence&#039; within the form&#039;s environment as long as the form remains &#039;loaded&#039;.&lt;/p&gt;
&lt;p&gt;5) Realization that from my controlling sub I could invoke a named &quot;form sub&quot; by merely referencing it by name as if the name were a form&#039;s &quot;property&quot;.  In Erik&#039;s example, he used &quot;F.Display&quot; in his controlling sub to invoke the form&#039;s &quot;Public Sub Display()&quot; routine.  I didn&#039;t know I could do that.  It enabled me to put into my own project&#039;s &quot;F.Display&quot; routine a call to my ListBox logic residing in yet a separate sub also behind the form.&lt;/p&gt;
&lt;p&gt;6) And of course, the final objective in my case was to have my controlling sub obtain knowledge of the selected listbox item.  And the key there is to not unload the form quite yet when you&#039;re finished with listbox item selection but merely hide it for a few more seconds until control passes from form back to your controlling routine at which point you invoke one final request of the form environment -- the &quot;Get Result&quot; property in Erik&#039;s example, where &quot;Result&quot; merely equates itself to any of the previously-used named values from the form routines (txbResult in Erik&#039;s example).&lt;/p&gt;
&lt;p&gt;In summary, the light that came on for me was the realization that I could separately pass named property arguments from my controlling routine to the form as many times as necessary prior to invoking a form routine that could subsequently execute additional &quot;form&quot; logic (e.g., find specific data values from a table and load them into the listbox contents) while making use of the previously-passed arguments to help in that effort, and then actually show the form.&lt;/p&gt;
&lt;p&gt;Hope that helps.  And a Huge Thank You to Erik!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Erik Eckhardt&#8217;s succinct example (March 3, 2006) of passing multiple parameters to a form via form properties was exactly what I was looking for when nothing else seemed to explain the sequence of events that take place during communication between sub and form module&#8217;s &#8220;properties&#8221; and the form itself.</p>
<p>After setting up his example, I followed breakpoints throughout execution of the program and plotted 12 steps that occur starting with the &#8220;Set F = New frmValuePass&#8221; and ending with &#8220;Set F = Nothing&#8221; and suddenly the light came on.  I sketched it out on paper and then applied same structure to my own code &amp; form and within an hour had accomplished what I&#8217;d struggled with for about 2 days.</p>
<p>My problem seemed to be figuring out how to load up a listbox of a form prior to showing the form but where the listbox&#8217;s &#8220;AddItem&#8221; logic needed some passed arguments from my main sub in order to know what to add to the listbox, and needed other passed arguments to be merely displayed on the form once shown (text box, labels, etc.).  I kept trying to figure out how to use a form&#8217;s &#8220;initialize&#8221; routine to invoke the ListBox logic, which was of course way too soon IF one needs to 1st pass several arguments to the form&#8217;s environment.</p>
<p>Just in case someone else reading thru this is struggling as I was with the issue of passing multiple arguments to a form via properties (the &#8220;recommended&#8221; method) prior to the form&#8217;s execution, I&#8217;ll try to enunciate the key points that were eluding me, a 1st-time form-with- listbox user (some of this is spelled out in Erik&#8217;s self-documented code):</p>
<p>[This will all make much more sense if you code up Erik's example -- including every single one of his embedded comments -- and then set breakpoints at everything in the controlling sub and everything in the form's property routines and subs and then monitor the code as it executes.  You can read his comments during breakpoint pauses and make your own notes and likely not even bother with anything else I have to say below.]</p>
<p>1) It helped when I categorized the &#8220;sequential events&#8221; in 3 visual columns:<br />
  a) Sub events (controlling sub)<br />
  b) Form Properties &amp; Form Sub events<br />
  c) Form itself<br />
   The &#8220;sequential events&#8221; will zig-zag from column-to-column during execution</p>
<p>2) The form doesn&#8217;t really require an &#8220;initialize&#8221; routine prior to passing it some property values.  As Erik pointed out, mere instantiation is enough in the sub&#8217;s &#8220;Set F = New frmValuePass&#8221; statement.  Turns out I didn&#8217;t need to execute &#8220;ListBox AddItem&#8221; logic until immediately prior to the &#8220;Show&#8221; command.</p>
<p>3) The sub&#8217;s invoking of a specific property&#8217;s &#8220;Let&#8221; routine in the form module will regain control of events immediately after the &#8220;Let&#8221; routine is executed.  i.e., the controlling sub&#8217;s &#8220;F.Value1 = 8? invokes the corresponding &#8220;Let&#8221; routine in the form module at which point control returns to the sub.  And realize that this can be done repeatedly as many times as needed by the controlling sub (hence multiple arguments passed to the form).</p>
<p>4) Realization that by using the &#8220;Let&#8221; properties to &#8220;hold&#8221; the passed argument in a separately-named argument, the named argument (and not the property name itself) is where the passed argument will be made available later down the road in your form&#8217;s logic WITHOUT a requirement to use a GET routine.  i.e., &#8220;gValue1 = TheValue&#8221; in Erik&#8217;s &#8220;Let Value1? routine stages the passed argument in &#8220;gValue1? which demonstrates &#8216;persistence&#8217; within the form&#8217;s environment as long as the form remains &#8216;loaded&#8217;.</p>
<p>5) Realization that from my controlling sub I could invoke a named &#8220;form sub&#8221; by merely referencing it by name as if the name were a form&#8217;s &#8220;property&#8221;.  In Erik&#8217;s example, he used &#8220;F.Display&#8221; in his controlling sub to invoke the form&#8217;s &#8220;Public Sub Display()&#8221; routine.  I didn&#8217;t know I could do that.  It enabled me to put into my own project&#8217;s &#8220;F.Display&#8221; routine a call to my ListBox logic residing in yet a separate sub also behind the form.</p>
<p>6) And of course, the final objective in my case was to have my controlling sub obtain knowledge of the selected listbox item.  And the key there is to not unload the form quite yet when you&#8217;re finished with listbox item selection but merely hide it for a few more seconds until control passes from form back to your controlling routine at which point you invoke one final request of the form environment &#8212; the &#8220;Get Result&#8221; property in Erik&#8217;s example, where &#8220;Result&#8221; merely equates itself to any of the previously-used named values from the form routines (txbResult in Erik&#8217;s example).</p>
<p>In summary, the light that came on for me was the realization that I could separately pass named property arguments from my controlling routine to the form as many times as necessary prior to invoking a form routine that could subsequently execute additional &#8220;form&#8221; logic (e.g., find specific data values from a table and load them into the listbox contents) while making use of the previously-passed arguments to help in that effort, and then actually show the form.</p>
<p>Hope that helps.  And a Huge Thank You to Erik!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Harrison</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-32418</link>
		<dc:creator>Craig Harrison</dc:creator>
		<pubDate>Sat, 17 May 2008 11:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-32418</guid>
		<description>&lt;p&gt;NVM I just declared it in the word document coding were i show the first form and its working fine when i set it to public, not exactly ideal coding but it works and its work computers so no memory problems&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>NVM I just declared it in the word document coding were i show the first form and its working fine when i set it to public, not exactly ideal coding but it works and its work computers so no memory problems</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Harrison</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-32417</link>
		<dc:creator>Craig Harrison</dc:creator>
		<pubDate>Sat, 17 May 2008 10:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-32417</guid>
		<description>&lt;p&gt;I have a two userform system, I want to pass a name from one userform to another, the name is filled in a txt box and used in the userform1 to fill in details to a word document and then i want to pass it to userform2 to be used as part of an output string depending upon choices made in userform2. How would i do this?&lt;br&gt;
I just need to know how i&#039;d declare the variable and pass it over.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I have a two userform system, I want to pass a name from one userform to another, the name is filled in a txt box and used in the userform1 to fill in details to a word document and then i want to pass it to userform2 to be used as part of an output string depending upon choices made in userform2. How would i do this?<br />
I just need to know how i&#8217;d declare the variable and pass it over.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik Eckhardt</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-19064</link>
		<dc:creator>Erik Eckhardt</dc:creator>
		<pubDate>Fri, 03 Mar 2006 21:58:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-19064</guid>
		<description>&lt;p&gt;&#039;Create a new workbook. Add a module with the following code:&lt;br&gt;
&#039;---------------&lt;br&gt;
Option Explicit&lt;/p&gt;
&lt;p&gt;Sub FormVariablePassingExample()&lt;br&gt;
    Dim F As frmValuePass &#039;just creates a variable, doesn&#039;t instantiate anything&lt;br&gt;
    Set F = New frmValuePass &#039;instantiates the form, but because it&#039;s hidden, code execution continues&lt;br&gt;
    F.Value1 = 8 &#039;set some values&lt;br&gt;
    F.Value2 = 6&lt;br&gt;
    &#039;You don&#039;t have to have one property per value. You could use an array. Or a publicly defined&lt;br&gt;
    &#039;   type (like a C structure: Type TypeName // Variables // End Type.&lt;br&gt;
    &#039;   or an object. Or a delimited string. Whatever.&lt;/p&gt;
&lt;p&gt;    F.Display &#039;This is a custom method on the form which gets it ready and does the .show&lt;br&gt;
    &#039;You could use .show directly, but I used this method to give the form a chance&lt;br&gt;
    &#039;  to know I was done passing values in so it could do some setup.&lt;br&gt;
    &#039;Code execution suspends here until the form is hidden (becomes invisible) again.&lt;br&gt;
    &#039;Clicking OK on the form makes the form hide, thereby resuming code execution.&lt;/p&gt;
&lt;p&gt;    Debug.Print F.Result &#039;we can look at the form or get values out to our heart&#039;s content&lt;br&gt;
    &#039;Note that the value printed out is whatever was in the textbox when you clicked close.&lt;br&gt;
    &#039;It&#039;s good practice to use something like this Result property instead of examining the&lt;br&gt;
    &#039;  textbox directly. What if you change how your form functions or does its job? Better&lt;br&gt;
    &#039;  to observe the &quot;Law of Demeter&quot; and only use properly defined interfaces to the form&#039;s&lt;br&gt;
    &#039;  data, instead of depending on knowing details about what&#039;s inside the form.&lt;/p&gt;
&lt;p&gt;    Set F = Nothing &#039;now actually unload the form, by removing all references to it.&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;&#039; Next, create a new form called frmValuePass&lt;br&gt;
&#039; give it any caption you like.&lt;br&gt;
&#039; Add a textbox and name it txbResult&lt;br&gt;
&#039; Add a button called btnOK and make it the Default button&lt;br&gt;
&#039; Add the following code:&lt;br&gt;
&#039;---------------&lt;/p&gt;
&lt;p&gt;Option Explicit&lt;/p&gt;
&lt;p&gt;Private gValue1 As Long&lt;br&gt;
Private gValue2 As Long&lt;/p&gt;
&lt;p&gt;Public Property Let Value1(TheValue As Long)&lt;br&gt;
    gValue1 = TheValue&lt;br&gt;
End Property&lt;/p&gt;
&lt;p&gt;Public Property Let Value2(TheValue As Long)&lt;br&gt;
    gValue2 = TheValue&lt;br&gt;
End Property&lt;/p&gt;
&lt;p&gt;Public Sub Display()&lt;br&gt;
    txbResult = gValue1 * gValue2&lt;br&gt;
    Me.Show&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Public Property Get Result() As Long&lt;br&gt;
    Result = Val(txbResult)&lt;br&gt;
End Property&lt;/p&gt;
&lt;p&gt;Private Sub btnOK_Click()&lt;br&gt;
    Me.Hide&lt;br&gt;
End Sub&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>&#8216;Create a new workbook. Add a module with the following code:<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Option Explicit</p>
<p>Sub FormVariablePassingExample()<br />
    Dim F As frmValuePass &#8216;just creates a variable, doesn&#8217;t instantiate anything<br />
    Set F = New frmValuePass &#8216;instantiates the form, but because it&#8217;s hidden, code execution continues<br />
    F.Value1 = 8 &#8216;set some values<br />
    F.Value2 = 6<br />
    &#8216;You don&#8217;t have to have one property per value. You could use an array. Or a publicly defined<br />
    &#8216;   type (like a C structure: Type TypeName // Variables // End Type.<br />
    &#8216;   or an object. Or a delimited string. Whatever.</p>
<p>    F.Display &#8216;This is a custom method on the form which gets it ready and does the .show<br />
    &#8216;You could use .show directly, but I used this method to give the form a chance<br />
    &#8216;  to know I was done passing values in so it could do some setup.<br />
    &#8216;Code execution suspends here until the form is hidden (becomes invisible) again.<br />
    &#8216;Clicking OK on the form makes the form hide, thereby resuming code execution.</p>
<p>    Debug.Print F.Result &#8216;we can look at the form or get values out to our heart&#8217;s content<br />
    &#8216;Note that the value printed out is whatever was in the textbox when you clicked close.<br />
    &#8216;It&#8217;s good practice to use something like this Result property instead of examining the<br />
    &#8216;  textbox directly. What if you change how your form functions or does its job? Better<br />
    &#8216;  to observe the &#8220;Law of Demeter&#8221; and only use properly defined interfaces to the form&#8217;s<br />
    &#8216;  data, instead of depending on knowing details about what&#8217;s inside the form.</p>
<p>    Set F = Nothing &#8216;now actually unload the form, by removing all references to it.<br />
End Sub</p>
<p>&#8216; Next, create a new form called frmValuePass<br />
&#8216; give it any caption you like.<br />
&#8216; Add a textbox and name it txbResult<br />
&#8216; Add a button called btnOK and make it the Default button<br />
&#8216; Add the following code:<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Option Explicit</p>
<p>Private gValue1 As Long<br />
Private gValue2 As Long</p>
<p>Public Property Let Value1(TheValue As Long)<br />
    gValue1 = TheValue<br />
End Property</p>
<p>Public Property Let Value2(TheValue As Long)<br />
    gValue2 = TheValue<br />
End Property</p>
<p>Public Sub Display()<br />
    txbResult = gValue1 * gValue2<br />
    Me.Show<br />
End Sub</p>
<p>Public Property Get Result() As Long<br />
    Result = Val(txbResult)<br />
End Property</p>
<p>Private Sub btnOK_Click()<br />
    Me.Hide<br />
End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rembo</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-18070</link>
		<dc:creator>Rembo</dc:creator>
		<pubDate>Tue, 03 Jan 2006 11:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-18070</guid>
		<description>&lt;p&gt;If you have to use multiple variables or if you want to save their values along with your workbook you might as well use a worksheet to store values. Simply use a cell as a variable. If you want you can name cells or ranges as well, whatever suites you best. This is used for example to create/store menu bars.&lt;/p&gt;
&lt;p&gt;A small example:&lt;/p&gt;
&lt;p&gt;*** workbook ***&lt;br&gt;
Private Sub Workbook_Open()&lt;br&gt;
    Dim i As Integer, i2 As Integer&lt;br&gt;
    Dim bWksExists As Boolean&lt;br&gt;
    i2 = Worksheets.Count&lt;br&gt;
    For i = 1 To i2&lt;br&gt;
        If Worksheets(i).Name = &quot;wksMyVars&quot; Then&lt;br&gt;
            bWksExists = True&lt;br&gt;
        End If&lt;br&gt;
    Next i&lt;br&gt;
    If Not bWksExists Then&lt;br&gt;
        Worksheets.Add After:=Worksheets(i2)&lt;br&gt;
        With Worksheets(i2 + 1)&lt;br&gt;
            .Name = &quot;wksMyVars&quot;&lt;br&gt;
            .Visible = xlHidden&lt;br&gt;
        End With&lt;br&gt;
    End If&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;*** In a module ***&lt;br&gt;
Sub ShowForm()&lt;br&gt;
    With Worksheets(&quot;wksMyVars&quot;)&lt;br&gt;
        .Range(&quot;A1?).Value = &quot;Greeting&quot;&lt;br&gt;
        .Range(&quot;B1?).Value = &quot;Hello World&quot;&lt;br&gt;
    End With&lt;br&gt;
    &#039; (A1 is set to Greeting for readability of the worksheet itself)&lt;br&gt;
    UserForm1.Show&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;*** UserForm1.CommandButton1 ***&lt;br&gt;
Private Sub CommandButton1_Click()&lt;br&gt;
    Dim sGreeting As String&lt;br&gt;
    sGreeting = Worksheets(&quot;wksMyVars&quot;).Range(&quot;B1?).Value&lt;br&gt;
    MsgBox sGreeting&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Rembo&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>If you have to use multiple variables or if you want to save their values along with your workbook you might as well use a worksheet to store values. Simply use a cell as a variable. If you want you can name cells or ranges as well, whatever suites you best. This is used for example to create/store menu bars.</p>
<p>A small example:</p>
<p>*** workbook ***<br />
Private Sub Workbook_Open()<br />
    Dim i As Integer, i2 As Integer<br />
    Dim bWksExists As Boolean<br />
    i2 = Worksheets.Count<br />
    For i = 1 To i2<br />
        If Worksheets(i).Name = &#8220;wksMyVars&#8221; Then<br />
            bWksExists = True<br />
        End If<br />
    Next i<br />
    If Not bWksExists Then<br />
        Worksheets.Add After:=Worksheets(i2)<br />
        With Worksheets(i2 + 1)<br />
            .Name = &#8220;wksMyVars&#8221;<br />
            .Visible = xlHidden<br />
        End With<br />
    End If<br />
End Sub</p>
<p>*** In a module ***<br />
Sub ShowForm()<br />
    With Worksheets(&#8220;wksMyVars&#8221;)<br />
        .Range(&#8220;A1?).Value = &#8220;Greeting&#8221;<br />
        .Range(&#8220;B1?).Value = &#8220;Hello World&#8221;<br />
    End With<br />
    &#8216; (A1 is set to Greeting for readability of the worksheet itself)<br />
    UserForm1.Show<br />
End Sub</p>
<p>*** UserForm1.CommandButton1 ***<br />
Private Sub CommandButton1_Click()<br />
    Dim sGreeting As String<br />
    sGreeting = Worksheets(&#8220;wksMyVars&#8221;).Range(&#8220;B1?).Value<br />
    MsgBox sGreeting<br />
End Sub</p>
<p>Rembo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-18022</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Wed, 28 Dec 2005 21:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-18022</guid>
		<description>&lt;p&gt;Greg -&lt;/p&gt;
&lt;p&gt;The &quot;official&quot; way to do this, which isn&#039;t much different than what you&#039;re doing, is to use a property procedure in the user form (or other class module). Then use a userform.show command in the calling procedure. There are property let (or set) procedures to assign values to a form&#039;s property, and property get procedures to retrieve these properties from a form. I&#039;ve written a short article on the topic:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://peltiertech.com/Excel/PropertyProcedures.html&quot; rel=&quot;nofollow&quot;&gt;http://peltiertech.com/Excel/PropertyProcedures.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;- Jon&lt;br&gt;
-----&lt;br&gt;
Jon Peltier, Microsoft Excel MVP&lt;br&gt;
Peltier Technical Services&lt;br&gt;
Tutorials and Custom Solutions&lt;br&gt;
&lt;a href=&quot;http://PeltierTech.com/&quot; rel=&quot;nofollow&quot;&gt;http://PeltierTech.com/&lt;/a&gt;&lt;br&gt;
_______&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Greg -</p>
<p>The &#8220;official&#8221; way to do this, which isn&#8217;t much different than what you&#8217;re doing, is to use a property procedure in the user form (or other class module). Then use a userform.show command in the calling procedure. There are property let (or set) procedures to assign values to a form&#8217;s property, and property get procedures to retrieve these properties from a form. I&#8217;ve written a short article on the topic:</p>
<p><a href="http://peltiertech.com/Excel/PropertyProcedures.html" rel="nofollow">http://peltiertech.com/Excel/PropertyProcedures.html</a></p>
<p>- Jon<br />
&#8212;&#8211;<br />
Jon Peltier, Microsoft Excel MVP<br />
Peltier Technical Services<br />
Tutorials and Custom Solutions<br />
<a href="http://PeltierTech.com/" rel="nofollow">http://PeltierTech.com/</a><br />
_______</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg F</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-17970</link>
		<dc:creator>Greg F</dc:creator>
		<pubDate>Sun, 25 Dec 2005 15:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-17970</guid>
		<description>&lt;p&gt;Here is a way I have used that is a bit unconventional. In fact, I have never seen anybody do this. I am wondering if I am missing some potential pit falls. &lt;/p&gt;
&lt;p&gt;******************** Userform1 *******************&lt;br&gt;
Option Explicit&lt;br&gt;
Dim LocalVar as String&lt;/p&gt;
&lt;p&gt;Private Sub UserForm_Initialize()&lt;br&gt;
&#039; Initialization code here&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Sub MyVariable (ByVal MyVal as String)&lt;br&gt;
LocalVar = MyVal&lt;br&gt;
Userform1.Show&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;**************************************************&lt;/p&gt;
&lt;p&gt;To pass the variable to the Userform I call it with:&lt;/p&gt;
&lt;p&gt;Sub MainPgrm()&lt;br&gt;
Dim MyVal as String&lt;br&gt;
MyVal = &quot;Some text&quot;&lt;/p&gt;
&lt;p&gt;Userform1.MyVariable MyVal&lt;/p&gt;
&lt;p&gt;End Sub&lt;/p&gt;
&lt;p&gt;The call first executes the &quot;Private Sub UserForm_Initialize()&quot;. It then goes to the &quot;MyVariable&quot; sub routine where the value is assigned to a local variable. If you don&#039;t precede the call to MyVariable with Userform1 it doesn&#039;t work. Is there a reason I should not pass variables to a userform this way?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here is a way I have used that is a bit unconventional. In fact, I have never seen anybody do this. I am wondering if I am missing some potential pit falls. </p>
<p>******************** Userform1 *******************<br />
Option Explicit<br />
Dim LocalVar as String</p>
<p>Private Sub UserForm_Initialize()<br />
&#8216; Initialization code here<br />
End Sub</p>
<p>Sub MyVariable (ByVal MyVal as String)<br />
LocalVar = MyVal<br />
Userform1.Show<br />
End Sub</p>
<p>**************************************************</p>
<p>To pass the variable to the Userform I call it with:</p>
<p>Sub MainPgrm()<br />
Dim MyVal as String<br />
MyVal = &#8220;Some text&#8221;</p>
<p>Userform1.MyVariable MyVal</p>
<p>End Sub</p>
<p>The call first executes the &#8220;Private Sub UserForm_Initialize()&#8221;. It then goes to the &#8220;MyVariable&#8221; sub routine where the value is assigned to a local variable. If you don&#8217;t precede the call to MyVariable with Userform1 it doesn&#8217;t work. Is there a reason I should not pass variables to a userform this way?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Miller</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/07/22/passing-arguments-to-a-userform/#comment-2045</link>
		<dc:creator>Andy Miller</dc:creator>
		<pubDate>Mon, 02 Aug 2004 16:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=695#comment-2045</guid>
		<description>&lt;p&gt;&lt;i&gt;Passing arguments to forms is great, but how to make form to return value back to his creator? &lt;/i&gt;&lt;/p&gt;
&lt;p&gt;This could be a post/thread in itself. The basic answer is that you need to add a Get statement and then access it as a property of the class like you would any other class/control/form (e.g. frmEmployees.Caption, frmEmployees.txtLastName.Text, or clsEmployee.LastName).&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><i>Passing arguments to forms is great, but how to make form to return value back to his creator? </i></p>
<p>This could be a post/thread in itself. The basic answer is that you need to add a Get statement and then access it as a property of the class like you would any other class/control/form (e.g. frmEmployees.Caption, frmEmployees.txtLastName.Text, or clsEmployee.LastName).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

