+ Reply to Thread
Results 1 to 2 of 2

Assign Page size to Custom page by Name

  1. #1
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Assign Page size to Custom page by Name

    Hi.
    When I use custom paper size, firstly I define it for the printer by
    Providing a name with page length and width and then Windows assigns to it a code
    number.

    Like i Created Custom size with name "SMALL LABEL(4x2)" and system assigned to a code number 257

    I have used this code in my VBA CODE like
    Please Login or Register  to view this content.
    it worked fine in my pc.

    but i tried the same Macro in other pc by creating the same custom size with same name as SMALL LABEL(4x2)
    my code did not worked since in that PC system assigned it to a different code 262

    so i am unable to catch this code in every pc since code is not same in all pc's

    Is there any way in VBA to refer to a
    custom paper size by its name?
    Last edited by naveenmarapaka; 02-27-2018 at 04:53 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Assign Page size to Custom page by Name

    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.
    Please Login or Register  to view this content.
    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:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Changing Page Size - Only gives label size options
    By etouch in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 01-31-2016, 02:40 PM
  2. Macro - Custom Footer Page # of Page ##
    By pschultz614 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-17-2015, 05:09 PM
  3. Auto size a pivot table to a page size
    By *.* in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-23-2006, 12:09 AM
  4. how do I re-size my web page?
    By Durango in forum Excel General
    Replies: 0
    Last Post: 01-02-2006, 04:20 PM
  5. [SOLVED] change cell size from page to page on the same worksheet
    By Danny in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-15-2005, 03:25 PM
  6. custom page size
    By janicet in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 10-01-2005, 07:05 PM
  7. [SOLVED] How do I set a custom page size in Excel
    By Ben Swift in forum Excel General
    Replies: 3
    Last Post: 08-23-2005, 07:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1