How can I clean the buffer from the folder picker?

  • Thread starter Thread starter Excel 009
  • Start date Start date
What I meant
program = Subs
workbook = Excel file

When the program finishs, a public variable will be terminated, but I
want to know if there is a way to keep it still alive.

Here is an example:

Say this is the only code in my module in the whole project.

Public strX as String

Function getString(str as String) as String
strX = str
getString = strX
End Function

Sub x()
Msgbox getString
End Sub

After I ran Sub x(), the

The message came up and after I click Ok, the program terminated. stX
is lost.
I want to know if there is a way to keep it still alive (not store it
physically some where, but only in memory).
 
Change your code slightly yo that below. Then call it repaeted from the
button click. The value of the variable is retianed.
I just thought; you're not using End anywhere in your code are you ? Because
that clear all variables.

NickHK

'<Worksheet code>
Private Sub CommandButton3_Click()
Call x
End Sub
'</Worksheet code>

'< Module code>
Public strX As String

Sub x()
If Len(strX) = 0 Then
MsgBox getString("New Value")
Else
MsgBox "the value of strX is " & Chr(34) & strX & Chr(34)
End If
End Sub

Function getString(str As String) As String
strX = str
getString = strX
End Function
'</ Module code>

NickHK
 
Thanks, Nick. What I need to know is a way to retain the StrX value
after all the subs finished running.

For example, I created

Sub y()
MsgBox strX
End Sub

in additional to your code. When I clicked the button, the message
comes up with the StrX value. After I clicked "OK" on the message box,
the sub finishs.

Now I run Sub Y. The message is blank because the StrX value is not
retained. In the situation where the Folder Picker is used, the value
is still there.
 
Back
Top