Results 1 to 10 of 19

Thread: Printing range of sheets in excel or in PDF

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    Try this. untested.

    Code:
    Sub Print_Ranges()
    
        Dim strShtname As String, strRngName As String
        Dim i As Long, strFileName  As String
        
            
        With Worksheets("INDEX")
            
            'sort the named range list according to page number order
            .Range("A2").CurrentRegion.Sort key1:=Range("A3"), order1:=xlAscending, Header:=xlYes, ordercustom:=1, Orientation:=xlTopToBottom
        
            'loop through the cells and determine parent of named range and specific range addresses
            For i = 3 To 38
                strRngName = .Cells(i, 2).Text
                strShtname = Range(strRngName).Parent.Name
                strFileName = ThisWorkbook.Path & "\" & strShtname & Format(Date, "mm-dd-yy") & ".pdf"
                'clear any existing print areas and reset to named ranges areas
                With Worksheets(strShtname)
                    .PageSetup.PrintArea = ""
                    .PageSetup.PrintArea = Range(strRngName).Address
                    .PrintOut
                  '  .PrintPreview
                    
                    '// Save the print area as a PDF file
                    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, _
                        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                        IgnorePrintAreas:=False, OpenAfterPublish:=False
                End With
            Next i
        End With
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  2. #2
    Member
    Join Date
    Apr 2011
    Posts
    69
    Rep Power
    15
    Thanks, I will test this..
    Can this code be changed to do this saving in excel file. in fact all the ranges are in named sheet and i want to extract them in same named sheet and save them as flat file without formulas (for circulation) and leaving other sheets where named ranges are not taken in 1 to 38.

    I would much appreciate that.

    Thanks once again.
    ----
    excel_learner
    (Using XL 2007 & 2010)

    -------Learning never stops!

Similar Threads

  1. Replies: 3
    Last Post: 05-14-2013, 03:25 PM
  2. Replies: 2
    Last Post: 04-14-2013, 08:23 PM
  3. Print excel sheet to a PDF file
    By xander1981 in forum Excel Help
    Replies: 2
    Last Post: 12-14-2012, 02:16 PM
  4. Replies: 7
    Last Post: 08-08-2012, 10:24 AM
  5. Printing Sheets Based On Criteria VBA
    By excel_learner in forum Excel Help
    Replies: 1
    Last Post: 05-04-2011, 08:00 PM

Posting Permissions

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