getting value from userform

  • Thread starter Örjan Skoglösa
  • Start date
Ö

Örjan Skoglösa

Hi,

How do I get a value from an userform module to a macro module?

I show a userform from a procedure in a "normal" module and after the
userform is hidden, I want to use the values of the userform controls
(e.g. whether or not checkboxes have been checked) in the rest of the
procedure, but they are emptied when the userform is hidden.

I have tried to put the values into variables while the userform is
active and to dimension the variables in different ways, but to no
avail.

Many thanks in advance.

Örjan Skoglösa
 
D

Doug Robbins - Word MVP

Hi Örjan,

You can store the values as variables in the document using

ActiveDocument.Variables("varname").Value = [your data]

to retrieve the data use

[the data] = ActiveDocument.Variables("varname").Value

If storing them in the ActiveDocument is not appropriate, you could use the
System.PrivateProfileString to store them in an .ini file or .txt file from
where they will be accessible, virtually no matter what. That would be done
by:

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", "varname") =
[your data]

to retrieve the data use

[the data] = System.PrivateProfileString("C:\Settings.txt", "MacroSettings",
"varname")


Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
 
H

Henry

Örjan,

Declare your variables as Global at the top of your module (In the General
Declarations area).
E.g. Global Myvar as Integer
Set them to zero or Null before you open your Userform
E.g. Myvar = 0
Do not Dim them anywhere in the Userform code.
Set them to what you want in the Userform code.
E.g. Myvar = 3
When the Userform is closed, the variables will still be set for use
elsewhere.

HTH
Henry
 
Ö

Örjan Skoglösa

Thank you very much Doug and Henry,

I tried both solutions and they both worked out very well.

I guess the difference is, that with PrivatProfileString I will be
able to "reload" choosen settings the next time the userform is shown,
even if the application is exited in between.

Best regards,

Örjan

On Sun, 6 Jul 2003 08:40:33 +1000, "Doug Robbins - Word MVP"
If storing them in the ActiveDocument is not appropriate, you could use the
System.PrivateProfileString to store them in an .ini file or .txt file from
where they will be accessible, virtually no matter what. That would be done
by:

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", "varname") =
[your data]

to retrieve the data use

[the data] = System.PrivateProfileString("C:\Settings.txt", "MacroSettings",
"varname")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top