+ Reply to Thread
Results 1 to 9 of 9

Printing Employees per Manager

Hybrid View

  1. #1
    Registered User
    Join Date
    11-24-2015
    Location
    Cleveland, Ohio
    MS-Off Ver
    2016
    Posts
    28

    Printing Employees per Manager

    Hello,

    In the example file I am trying to come up with a way so that a manager can print a report showing which employees fall under which manager and their salaries.

    So in the file I have Managers 1,2,3, & 4 and various employees.

    I have the basic print VBA set up, I am just not sure how to approach the select statement. Any help is much appreciated.

    Sub PrintArea()
    
    Range("A:A").Select
    Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "Employees.pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    True
    
    With ActiveSheet.PageSetup
    .Zoom = False
    .Orientation = xlLandscape
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Printing Employees per Manager

    Wouldn't it be easier (and more stable) to just use a filter? Highlight your data & headers, select "filter", then use the filter to control which entries are visible?

    Per the request, though, I modified your procedure to the version below, which should filter the data by manager, then export it to a pdf. It wasn't clear how you wanted the user to select which manager, though, so it goes with whichever manager name is selected when the macro is run. The snippet you posted doesn't actually print, so mine doesn't either, it just opens the preview. Is that (roughly) what you were after?

    Sub PrintArea()
    Dim Manager As String
    
    Manager = ActiveCell.Value
    Worksheets("Data").Range("A:D").AutoFilter _
     field:=1, _
     Criteria1:=Manager, _
     VisibleDropDown:=True
    
    Range("A:D").Select
    Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "Employees.pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, OpenAfterPublish:=True
    
    With ActiveSheet.PageSetup
    .Zoom = False
    .Orientation = xlLandscape
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    End Sub

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Printing Employees per Manager

    I think the .PageSetup code block should be before the .ExportAsFixedFormat.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Printing Employees per Manager

    Quote Originally Posted by AlphaFrog View Post
    I think the .PageSetup code block should be before the .ExportAsFixedFormat.
    True. If you want the PageSetup bit, it certainly won't do much good after the export. Apologies for the sloppiness.

  5. #5
    Registered User
    Join Date
    11-24-2015
    Location
    Cleveland, Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: Printing Employees per Manager

    Thank you, I will give this a try. Yes I would personally use the filters but management needs for it to be as simple as possible (for obvious reasons). So when they open up the sheet, they can click a button - it will print to a pdf so they can hand them out.

    They struggle with highlighting certain cells ; )

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Printing Employees per Manager

    Hi DK

    I had started on this earlier and got interrupted by the Roofing Contractor (hail damage).

    Here's an example using a User Form whereby the Manager will select the Manager Name and save the PDF. If you like it keep it...otherwise trash it.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  7. #7
    Registered User
    Join Date
    11-24-2015
    Location
    Cleveland, Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: Printing Employees per Manager

    Thank you so much Jaslake - perfect!

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Printing Employees per Manager

    You're welcome...glad I could help. Thanks for the Rep.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,352

    Re: Printing Employees per Manager

    Without the Userform. With 1 buttonclick pdf-file for every manager.
    Private Sub CommandButton1_Click()
        Application.ScreenUpdating = False
        sn = Cells(1).CurrentRegion.Value
        With CreateObject("scripting.dictionary")
            For i = 2 To UBound(sn)
                x0 = .Item(sn(i, 1))
            Next
            For j = 0 To .Count - 1
                fName = .keys()(j)
                Cells(1).CurrentRegion.AutoFilter 1, .keys()(j)
                With ActiveSheet.PageSetup
                    .Zoom = False
                    .Orientation = xlLandscape
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                End With
                ActiveSheet.ExportAsFixedFormat 0, ThisWorkbook.Path & "\" & fName & ".pdf"
            Next
        End With
        ActiveSheet.AutoFilterMode = False
        Application.ScreenUpdating = True
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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. sales manager & purchase manager sheets command button error
    By rana19 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-24-2016, 07:26 AM
  2. [SOLVED] Total count of employees depending on chosen manager
    By Harvey Raphael in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-17-2014, 03:44 AM
  3. Forecast How Many Employees To Hire Based on Active and Termed Employees
    By Kanook22 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-12-2014, 01:19 PM
  4. Replies: 10
    Last Post: 01-10-2014, 10:26 AM
  5. Assign Employees to Training Groups evenly based on Manager
    By eoexcel in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-16-2013, 05:18 PM
  6. Replies: 2
    Last Post: 03-11-2013, 09:59 PM
  7. [SOLVED] Printing leaves EXCEL.EXE process in Task Manager
    By eeidfn in forum Excel General
    Replies: 1
    Last Post: 02-27-2006, 10:30 PM

Tags for this Thread

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