ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   losing variable after "unload me" (https://www.excelbanter.com/excel-programming/310221-losing-variable-after-unload-me.html)

Steven K

losing variable after "unload me"
 
Hello,

I am using a form to gather information and assigning some of the
information to a variable to use as a file name. My problem is that I need
to unload the form before I can pragmatically save the file. But if I
unload the file, I lose the variable value "strCSVFile". Is there a way to
save the value even if you unload the form?

Private Sub cmdOK_Click()
...
strCSVFile = "some file name"
Unload Me
Call BuildCSVFile(strCSVFile)
...
ActiveWorkbook.SaveAs Filename:=strPath, FileFormat:=xlCSV,
CreateBackup:=False
End Sub

Any help would be appreciated.

--
Thanks in advance,

Steven



JE McGimpsey

losing variable after "unload me"
 
One way:

Hide rather than Unload the userform:

Private Sub cmdOK_Click()
...
strCSVFile = "some file name"
Me.Hide
Call BuildCSVFile(strCSVFile)
...
ActiveWorkbook.SaveAs _
Filename:=strPath, _
FileFormat:=xlCSV,
CreateBackup:=False
Unload Me
End Sub


In article ,
"Steven K" wrote:

Hello,

I am using a form to gather information and assigning some of the
information to a variable to use as a file name. My problem is that I need
to unload the form before I can pragmatically save the file. But if I
unload the file, I lose the variable value "strCSVFile". Is there a way to
save the value even if you unload the form?

Private Sub cmdOK_Click()
...
strCSVFile = "some file name"
Unload Me
Call BuildCSVFile(strCSVFile)
...
ActiveWorkbook.SaveAs Filename:=strPath, FileFormat:=xlCSV,
CreateBackup:=False
End Sub

Any help would be appreciated.



All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com