I have an excel sheet which has a button which when pressed shows up an userform where the user enters his credentials to login to a website from excel.
Now I am trying to add another sheet with another button which does the same functionality but login to another website. That is when user presses button in first sheet he should be able to login to first website, in case the userform is initialized from second page, user should be able to login to second website.
In short, is there a way for my VBA code to know from which page the userform was initialised.
In this case how can I reuse the same user form twice?
-
What code are you using?99moorem– 99moorem2015-06-30 15:29:27 +00:00Commented Jun 30, 2015 at 15:29
1 Answer
Here you can find Jon Peltier's explanation on using properties within user forms: User Form Properties
Using a property to establish which page the userform was initiated from, will enable your code to be cleaner and easier to update in the future. You will have something like:
Procedure1 is assigned to button1, which when pressed assigns a value to the userform property, and then calls the userform to enter credentials. The userform property allows you to identify that the user clicked button1, and thus wants to logon to website1. Similarly, if button2 is pressed, procedure2 is run, assigning a different value to the userform property, allowing the userform to know that once the credentials have been entered, the user wishes to logon to website2.
Hope that helps.