+ Reply to Thread
Results 1 to 6 of 6

Using VBA to print a dynamic range.

Hybrid View

j_Southern Using VBA to print a dynamic... 10-22-2012, 11:31 AM
shg Re: Using VBA to print a... 10-22-2012, 11:47 AM
j_Southern Re: Using VBA to print a... 10-22-2012, 12:12 PM
shg Re: Using VBA to print a... 10-22-2012, 04:01 PM
j_Southern Re: Using VBA to print a... 10-23-2012, 12:13 PM
shg Re: Using VBA to print a... 10-23-2012, 05:22 PM
  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Using VBA to print a dynamic range.

    Dear All,
    I am using the following code to select a defined dynamic range and to print it.
    As written here it fails with an error message saying that the method is not supported.
    Private Sub CommandButton1_Click()
    
    
       With Sheets("Envelope_List")
        ActiveSheet.PageSetup.PrintArea = Range("Envelope_List_Pivot")
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
       End With
    End Sub
    The code was arrived at by running a macro and changing the range details. If I run it as a macro it works.
    If I change the code to:-
    Private Sub CommandButton1_Click()
    Macro1
    End Sub
    It fails again as above.
    Where am I going wrong?
    John

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Using VBA to print a dynamic range.

    The PrintArea property is a string, not a range, so

    ActiveSheet.PageSetup.PrintArea = Range("Envelope_List_Pivot").Address
    or just

    Range("Envelope_List_Pivot").PrintOut
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Using VBA to print a dynamic range.

    shg,
    Thanks for your interest.
    I have tried
    With Sheets("Envelope_List")
    ActiveSheet.PageSetup.PrintArea = Range("Envelope_List_Pivot").Address
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
       End With
    and
       Range("Envelope_List_Pivot").Printout Copies: = 1
    Both give Error "application or object defined error"
    So I still don't quite understand.
    John

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Using VBA to print a dynamic range.

    In your first example, you have a With statement that doesn't do anything. Activesheet (obviously) and Range refer to the active sheet, not to Worksheets("Envelope_List"). You might instead use

        With Worksheets("Envelope_List")
            .PageSetup.PrintArea = .Range("Envelope_List_Pivot").Address
            .PrintOut Copies:=1
        End With
    I don't understand why the second example doesn't work for you. Is the range name valid?

  5. #5
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Using VBA to print a dynamic range.

    shg
    I am still in difficulty, with all your suggestions giving the application or object defined error. I am sure that the worksheet and range names are as stated. The range was defined as dynamic in the name manager using a formula like = Offset(Sheet1!($A$10,0,0,Counta(Sheet1!$A:$A),Counta(Sheet1!$5:$5)).
    The code is driven by a button click event.
    If you can think of anything else It would be very helpful.
    regards
    John

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Using VBA to print a dynamic range.

    Post a workbook that minimally illustrates the problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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