Hi naveenmarapaka,
Great question. You have to get the value from the Windows Registry. I was only able to test in Windows 10. The registry values in other versions of Windows may be different.
Try the following code. Of course the Custom Paper Size names have to be defined on each computer. The function below will return the number assigned by Windows. Please note that 'Custom Paper Sizes' are assigned to specific printers and not to Windows in general.
It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
This option requires all variables to be declared and will give a compiler error for undeclared variables.
Lewis
Bookmarks