I have a User Form on Excel with several controls and nested controls that I need to adjust depending on the resolution of the screen.
However after trying several codes to readjust the .Top .Left .Height .Width properties and even the .Font.Size so that the texts in the different controls would keep the same aspect ratio, I was unsuccessful.
After researching this and looking for answers and codes from several different sources I finally was able to write the necessary code to readjust the ratios.
I'm sorry but I'm really unable to cite the different sources because I also got them through a prolonged period of time and on different occasions.
The following code should be on a module of it's own.
Afterwards you need to use the adjustToRes function on the initialize event of the UserForm.
The adjustToRes function needs 3 required arguments and has 2 optional ones.
UserForm is obviously the UserForm object that needs resizing.
designScreenWidthPixels has to be the number of horizontal pixels of the screen for which the UserForm was designed.
For example if the UserForm was created using a screen with resolution of 1920*1080 then
designScreenHeightPixels would then be the number of vertical pixels of the screen for which the UserForm was designed.
In the case of this example that would be 1080.
The optional argument lowerLimitHeight is used to exit the function without any resizing if the vertical resolution of the current screen is less than lowerLimitHeight. If no argument is provided then by default lowerLimitHeight = 768.
The optional argument lowerLimitWidth does the same thing as lowerLimitHeight but concerning the horizontal resolution of the screen. If no argument is provided then by default lowerLimitHeight = 1024.
You can of course change this default values if it doesn't suit you.
The function adjustToRes returns False if no resizing was done, otherwise if no resizing was needed or the resizing was successfull then it returns True.