PDA

View Full Version : Recover variable value after saving document



brunces
06-29-2007, 07:27 AM
Friends,

I have this worksheet which, when it's opened, shows a login form. The user logs in and his information is saved in two public variables, strUser and strLevel, through VLOOKUP function (there's a table for users, passwords and levels).

Some sheets are reachable based on user's level (admin, user, guest).

The point is: When I save this worksheet (while it's opened, not before closing document) those public variables have their contents cleared. Then, nothing else works fine within the worksheet. So, I have to click on "Change User" button (it opens login form) and log in again, so that those variables are filled again.

Please, is there any way to avoid Excel from erasing those public variables contents? Or maybe, make it recover those values after saving document?

I don't know if this could be the right solution, but I've tried to copy those variables contents to cells in a sheet (using the event Worksheet_BeforeSave), so that I could tell the variables to recover their contents from those cells later. But, how do I do that automatically after saving?

Thank you very much for your attention. :)

Brunces

lucas
06-29-2007, 07:29 AM
post it please. Don't really want to reproduce your work to help you figure this out.

Paul_Hossler
06-29-2007, 08:13 AM
Could you save the information in the registry using SaveSetting, GetSetting?



' Place some settings in the registry.
SaveSetting "MyApp","Startup", "Top", 75
SaveSetting "MyApp","Startup", "Left", 50

Debug.Print GetSetting(appname := "MyApp", section := "Startup", _
key := "Left", default := "25")

DeleteSetting "MyApp", "Startup"

rbrhodes
06-29-2007, 02:28 PM
Hi,

How and where are you declaring the public variables? If you insert a standard module and declare them there they won't be lost on saving the sheet.

Cheers,

dr