+ Reply to Thread
Results 1 to 8 of 8

Can I define a printarea using a named range

  1. #1
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    Can I define a printarea using a named range

    I have the following code trying to define the conditions for a print out
    Please Login or Register  to view this content.
    This fails at .PrintArea = .Range(PrintMonth)
    with an error "object doesn't support this property or method"
    Can someone show me where I've gone wrong?
    John

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Can I define a printarea using a named range

    Hi there,

    Knee-jerk and untested suggestion, but try:

    Please Login or Register  to view this content.

    Without the highlighted addition, "Range(PrintMonth)" is regarded as being a (non-existent!) property of "PageSetup", not of the worksheet in question.

    Hope this helps.

    Regards,

    Greg M
    Last edited by Greg M; 06-15-2022 at 11:19 AM. Reason: "Without the . . . " added

  3. #3
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    Re: Can I define a printarea using a named range

    Greg M.
    Thanks for your interest in my problem.
    Unfortunately your suggestion didn't work.
    I have found an answer on the web though which is-
    Please Login or Register  to view this content.
    This works properly

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Can I define a printarea using a named range

    Hi again,

    Thanks for your feedback.

    Your solution doesn't work on my computer.

    As I mentioned before, using:

    Please Login or Register  to view this content.
    means that "Range(PrintMonth).Address" is regarded as a property of PageSetup - such a property does not exist, which is why the "Object doesn't support this property or method" is generated.


    To work correctly (on my computer anyway), the following code is used:

    Please Login or Register  to view this content.
    Apologies for not including .Address in my original post.


    Regards,

    Greg M

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Can I define a printarea using a named range

    If it's a named range, you should be able to just use:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Can I define a printarea using a named range

    Hi RoryA,

    I'm happy to be corrected on this, but I think that the PrintArea property holds a string value (i.e. an A1-style Address) rather than an object (i.e. a Named Range).

    Best regards to you,

    Greg M

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Can I define a printarea using a named range

    Yes - the use of .Range(PrintMonth) in the original code leads me to believe that the parameter passed is the name of the range?

  8. #8
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    Re: Can I define a printarea using a named range

    I don't quite know how my initial formulation, without the Sheets(SheetName) did work but I found that the code generated by the Macro had dozens of repeated lines.
    After the first run I cleaned this up and perhaps cleaned up an important reference to the sheet.
    Any how the following test code works and I will be able to add the bells and wistles I need.
    Please Login or Register  to view this content.
    Many thanks for your help (and persistence). This was my first taste of coding a print out and I needed the help
    John

+ 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. How to set PrintArea to a named range
    By Osprey2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2021, 11:27 AM
  2. excel macro range define to another sheet / named range
    By koi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2013, 10:25 AM
  3. VBA to Define Named Range Based on Conditions
    By Elwood07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2011, 11:57 AM
  4. Define named range where user can define size
    By nahousto in forum Excel General
    Replies: 4
    Last Post: 07-06-2009, 05:09 PM
  5. [SOLVED] define a Named Range
    By T. Jenkins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-08-2006, 04:05 PM
  6. [SOLVED] How to define a relative named range in VBA
    By John Broderick in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-24-2005, 11:10 AM
  7. How to define a Named Range in VBA?
    By Richard in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2005, 02:50 PM

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