Automation Of Reporting And Alerting

Post on 13-Nov-2014

948 views 5 download

Tags:

description

A look at a project to send automated emails. The processes behind it and how to do it yourself using 6 techniques: Secured folders, ODBC connections, Access queries, Excel Pivot tables, Excel macros and scheduled tasks

Transcript of Automation Of Reporting And Alerting

Automation of Reporting Automation of Reporting and Alertingand Alerting

MicrocosmMicrocosm

• The following presentation is an illustration of The following presentation is an illustration of most of my automation techniques in one project.most of my automation techniques in one project.

• It is a microcosm of an automated set of systems It is a microcosm of an automated set of systems I set up to;I set up to;– Illustrate and share data (in a secured location)Illustrate and share data (in a secured location)– Create audits (proactive and reactive)Create audits (proactive and reactive)– Trigger events (send emails)Trigger events (send emails)

TechniquesTechniques

1.1. Secured foldersSecured folders• Utilization of folder security instead of Excel passwordsUtilization of folder security instead of Excel passwords

2.2. ODBC ConnectionsODBC Connections• Creating real time links to the database tables of Creating real time links to the database tables of

applications.applications.

3.3. Access queriesAccess queries• Bringing data (tables) for one or many applications Bringing data (tables) for one or many applications

together.together.• Calculations being performed.Calculations being performed.

4.4. Excel Pivot tablesExcel Pivot tables• Illustrating data on a user friendly interface.Illustrating data on a user friendly interface.

5.5. Excel MacrosExcel Macros• Automation of the updating of spreadsheetsAutomation of the updating of spreadsheets• Automation of emails sent to the right people.Automation of emails sent to the right people.

6.6. Scheduled tasksScheduled tasks• Starting the macros, at night.Starting the macros, at night.

The projectThe project

• The project was to automate notifying employees (only The project was to automate notifying employees (only certain exempt emps) to submit timesheets.certain exempt emps) to submit timesheets.

• An HR rep was doing this in the past (for her location) and An HR rep was doing this in the past (for her location) and she wanted a program that did this, without her having she wanted a program that did this, without her having doing anything.doing anything.

• The task was to set up pivot tables that illustrated 2 The task was to set up pivot tables that illustrated 2 problems and with a summary and detail tab for each (4 problems and with a summary and detail tab for each (4 tabs total).tabs total).

1.1. Pay periods that had no submitted hours.Pay periods that had no submitted hours.2.2. Pay periods that had hours, but hade never been submitted.Pay periods that had hours, but hade never been submitted.

– Notifications were to be emailed automatically, every Notifications were to be emailed automatically, every Tuesday morning.Tuesday morning.

Final Spreadsheet (summary tab)Final Spreadsheet (summary tab)

Final Spreadsheet (detail tab)Final Spreadsheet (detail tab)

Email NotificationEmail Notification

GroundworkGroundwork

– The groundwork for this project had The groundwork for this project had already been laid by existing projects.already been laid by existing projects.

– The goal was just to copy existing molds The goal was just to copy existing molds and create new processes.and create new processes.

Folder securityFolder security

Folder securityFolder security

•In a shared location create a folder.

•Have your IT department create a security group on the folder.

•This replacing have an Excel password (and is more secure)

Folder securityFolder security

•The folder I used, already had security and a variety of confidential excel spreadsheets

Access EngineAccess Engine

Access EngineAccess Engine

•Access is going to be the powerhouse behind the process.

•It will access the tables (ODBC) and manipulate the data (queries), so they can be illustrated in Excel (pivot tables)

ODBC connectionODBC connection

ODBC connectionODBC connection

• ODBC connections are read only links to your ODBC connections are read only links to your applications tables.applications tables.

• Once your source is updated, your ODBCs will be.Once your source is updated, your ODBCs will be.

• Some applications, the ODBCs, are created upon Some applications, the ODBCs, are created upon installation. Others you will need your IT team to installation. Others you will need your IT team to create for you.create for you.

• These connections are similar to what a SQL These connections are similar to what a SQL programmer might work with (but read only).programmer might work with (but read only).

ODBC connectionODBC connection

•1st thing to do is access the data (tables) via an ODBC connection.

•I had already established these real-time links and researched what data was in what table and what their common denominators were.

•These tables were from our salaried timekeeping system (NetConsole)

ODBC connectionODBC connection

•Go to

•File•Get External Data•Link Tables

•If you select Import, it creates a static table, which is not automatically updated.

ODBC connectionODBC connection

•Change “Files of type:” to

•ODBC databases()

ODBC connectionODBC connection

•Select the Machine Data Source tab

•Select your database

ODBC connectionODBC connection

•A list of the tables will appear.

•Select the one you want.•This might involve a lot of trial and error. I usually select all and find out what each one contains.

ODBC connectionODBC connection

•Here is one of the opened tables for my timekeeping system.

•Most tables have “IDs” that correspond with other tables.

•You will need to know what these mean, when you create queries.

•Most developers create relationships at the table level, but I prefer to do that at the query level (next set of slides).

Access QueriesAccess Queries

Access QueriesAccess Queries

•The way I create queries, is by selecting;

•Create query in Design view

Access QueriesAccess Queries

•Select the tables of queries that you want to bring together

Access QueriesAccess Queries

•I had already created a base timesheet query, for other projects.

•So I could copy that base one and use that.

Access QueriesAccess Queries

•Once copied, select paste and name the new query

Access QueriesAccess Queries

•All of these tables get linked together by their “IDs” or a common denominator.

•In the end, they become one unified set of data.

•There is a lot of trail and error in this process and validation to know values.

Access QueriesAccess Queries

•Double click on the headers you want on you query.

Access QueriesAccess Queries

•Add criteria to narrow the range of the query.

Access QueriesAccess Queries

•Add formulas to perform your math.

•In this case I needed to change blanks caused by linking table and add create a total hours column.

•I used an IIF(IsNull) formula. It converts blank spaces to zeros, so that math can be performed.

Access QueriesAccess Queries•One of the tasks of the project was to find who hadn’t entered hours for a pay period. This isn’t tracked in our attendance system.

•This query assigned a period to every one.

•Example: John Doe has a row for every pay period, in all of the years for our time keeping system.

Access QueriesAccess Queries

•By linking a query that has all of the timekeeping data, with one that assigns pay period regardless if worked.

•We now have a query, that tells us, you didn’t enter time

Access QueriesAccess Queries

•Next is giving a value to hours entered and hours missing (per payperiod).

•We can track that on a pivot table and run macros off that data.

Excel Pivot TablesExcel Pivot Tables

Excel Pivot TablesExcel Pivot Tables

•Next is creating a pivot table that has sums of the pay periods missing, so an email can get generated.

Excel Pivot TablesExcel Pivot Tables

•To create a Pivot table

•Got to

•Data•PivotTable and PivotChart Report

Excel Pivot TablesExcel Pivot Tables

•Select

•External data source•Next

Excel Pivot TablesExcel Pivot Tables

•Select

•Get Data

Excel Pivot TablesExcel Pivot Tables

•Select

•MS Access Database

Excel Pivot TablesExcel Pivot Tables

•Navigate to folder location

•Select database

Excel Pivot TablesExcel Pivot Tables

•Select

•Table or query•Arrow (to move all headers over)•Next (next couple screens)

Excel Pivot TablesExcel Pivot Tables

•Select

•Finish

Excel Pivot TablesExcel Pivot Tables

•Select

•Next

Excel Pivot TablesExcel Pivot Tables

•Select

•Layout

Excel Pivot TablesExcel Pivot Tables

•Select

•Headers you displayed on the picot table

•Drag and drop

•Page area is a big filter

•Row and column area illustrate text and groups

•Data area does the math

Excel Pivot TablesExcel Pivot Tables

•Select

•Finish

Excel Pivot TablesExcel Pivot Tables

•A default view of your pivot will appear.

•I never use the default, so the next slides will show how to change it.

•At the same time a list of your header will appear. You can close these at any time.

Excel Pivot TablesExcel Pivot Tables

•If you don’t already have the pivot table toolbar, this would be a good time to add it.

•Select

•View•Toolbars•PivotTable

Excel Pivot TablesExcel Pivot Tables

•Select

•Format Report

•Scroll down and select Table1

•You can experiment and choose which one you like better.

Excel Pivot TablesExcel Pivot Tables

•Once you change the report type, the rows and columns can get mismatched.

•You can go back to the layout, by right click on the pivot and selecting wizard.

•Or, you can pick up the header and drag it, to where you want it.

Excel Pivot TablesExcel Pivot Tables

•Most items are defaulted to give subtotals.

•Which could be what you and could be an eye sore.

•To turn off the sub totals

•Right click on the data for that column and select Field Settings

Excel Pivot TablesExcel Pivot Tables

•Change Subtotals to None

Excel Pivot TablesExcel Pivot Tables

•If you don’t space between lines.

•Click on Layout

•Deselect Insert blank line after each item.

Excel Pivot TablesExcel Pivot Tables

•I only needed a couple people for this process, which I can filter on the name header.

•Select the pull down arrow.

•Select (Show All). This deselects everyone.

•Select the names you need for this process.

Excel Pivot TablesExcel Pivot Tables

•This is the finished version for the summary.

•This tab will drive my macro.

•For the detailed tab, you don’t need to redo the pivot table process.

•You just need to create a copy of the tab.

•Right click on tab and select Move or Copy

Excel Pivot TablesExcel Pivot Tables

•Click Create a copy and Ok

Excel Pivot TablesExcel Pivot Tables

•Right click anywhere on the pivot.

•Select Field List

Excel Pivot TablesExcel Pivot Tables

•Drag and drop Period next to Supervisor.

•There will be a gray line that acts as a guide.

Excel Pivot TablesExcel Pivot Tables

•Drag and drop NonSub on the Page field.

•This allows you to select certain items. You can select Field settings and hide items (like the zero).

Excel Pivot TablesExcel Pivot Tables

•I selected one, so it would only illustrate, names with out pay periods.

•Which was none in this case.

Excel Pivot TablesExcel Pivot Tables

•This is the summary tab for employees that didn’t enter any hours for a pay period.

Excel Pivot TablesExcel Pivot Tables

•This is the detail tab, which illustrates;

•The supervisor and their employees that have pay periods with missing hours.

•I added back in the subtotal for supervisor and name headers.

Excel MacrosExcel Macros

Excel MacrosExcel Macros

•I usually create a blank spreadsheet to house my macros.

•Hit ALT F11 to open the VBA screen.

Excel MacrosExcel Macros

•Create your code in a Module.

•Or you can use the recorder to create your macros.

•I do that for some of my stuff, but emailing requires writing the code.

Excel MacrosExcel Macros

Sub Diebold_email_start()Sub Diebold_email_start()''Application.DisplayAlerts = FalseApplication.DisplayAlerts = FalseApplication.ScreenUpdating = FalseApplication.ScreenUpdating = False On Error Resume Next 'turn error reporting offOn Error Resume Next 'turn error reporting offWorkbooks.Open Filename:="P:\Payroll\Anderson\Anderson_Billable.xls", Notify:=FalseWorkbooks.Open Filename:="P:\Payroll\Anderson\Anderson_Billable.xls", Notify:=False If ActiveWorkbook.ReadOnly = True ThenIf ActiveWorkbook.ReadOnly = True Then ActiveWorkbook.Close FalseActiveWorkbook.Close False ElseElse Sheets("NotEntered_Master").SelectSheets("NotEntered_Master").Select Range("A4").SelectRange("A4").Select ActiveSheet.PivotTables("PivotTable1").PivotCache.RefreshActiveSheet.PivotTables("PivotTable1").PivotCache.RefreshActiveWorkbook.SaveActiveWorkbook.Save Range("C5").SelectRange("C5").Select Dim x As IntegerDim x As Integer x = Range("C5")x = Range("C5") If x = 0 ThenIf x = 0 Then

ActiveWindow.CloseActiveWindow.Close

ElseElse

Application.Run "Anderson_Macro.xls!Diebold_email"Application.Run "Anderson_Macro.xls!Diebold_email"

End IfEnd If End IfEnd If Application.DisplayAlerts = TrueApplication.DisplayAlerts = TrueApplication.ScreenUpdating = TrueApplication.ScreenUpdating = True On Error GoTo 0 'turn error reporting backOn Error GoTo 0 'turn error reporting backEnd SubEnd Sub

•Like in Access, I had macros that did what I wanted, I just needed to copy them and change some info (in the colored boxes).

•This macro;

• Opens the spreadsheet just shown.•Refreshes the pivot table•Checks to see if Diebold (C5 on the pivot table) has a sum greater than zero•If it doesn’t it closes the spreadsheet•If it does it launches another macro

Excel MacrosExcel Macros

Sub Diebold_email()Sub Diebold_email()

Dim OutApp As ObjectDim OutApp As Object Dim OutMail As ObjectDim OutMail As Object Dim strbody As StringDim strbody As String Set OutApp = CreateObject("Outlook.Application")Set OutApp = CreateObject("Outlook.Application") OutApp.Session.LogonOutApp.Session.Logon Set OutMail = OutApp.CreateItem(0)Set OutMail = OutApp.CreateItem(0) strbody = "" & vbNewLine & vbNewLine & _strbody = "" & vbNewLine & vbNewLine & _ "You have not entered hours in NetConsole, for a prior period(s), please enter and submit these hours ASAP." & vbNewLine & _"You have not entered hours in NetConsole, for a prior period(s), please enter and submit these hours ASAP." & vbNewLine & _ "" & vbNewLine & _"" & vbNewLine & _ "" & vbNewLine & _"" & vbNewLine & _ """" On Error Resume NextOn Error Resume Next With OutMailWith OutMail .To = "Brian.Diebold@inergyautomotive.com".To = "Brian.Diebold@inergyautomotive.com" .CC = "Brenda.Dutton@inergyautomotive.com; Mohammad.Muqri@inergyautomotive.com".CC = "Brenda.Dutton@inergyautomotive.com; Mohammad.Muqri@inergyautomotive.com" .BCC = "".BCC = "" .Subject = "NetConsole Hours".Subject = "NetConsole Hours" .Body = strbody.Body = strbody .Send 'or use .Display.Send 'or use .Display End WithEnd With On Error GoTo 0On Error GoTo 0 Set OutMail = NothingSet OutMail = Nothing Set OutApp = NothingSet OutApp = Nothing ActiveWindow.CloseActiveWindow.CloseApplication.DisplayAlerts = TrueApplication.DisplayAlerts = TrueApplication.ScreenUpdating = TrueApplication.ScreenUpdating = True End SubEnd Sub

•This is the macro that is kicked off, when a sum is greater than zero.

•It sends an email to the appropriate people, with the appropriate message.

•This was another copy and paste, then change certain items.

Excel MacrosExcel Macros

Sub Email_NotEntered()Sub Email_NotEntered()''' Update Macro' Update Macro' Macro recorded 4/16/2009 by durochs' Macro recorded 4/16/2009 by durochs''Application.Run "Anderson_Macro.xls!Diebold_email_start"Application.Run "Anderson_Macro.xls!Diebold_email_start"Application.Run "Anderson_Macro.xls!Harris_email_start"Application.Run "Anderson_Macro.xls!Harris_email_start"Application.Run "Anderson_Macro.xls!Hulme_email_start"Application.Run "Anderson_Macro.xls!Hulme_email_start"Application.Run "Anderson_Macro.xls!Irwin_email_start"Application.Run "Anderson_Macro.xls!Irwin_email_start"Application.Run "Anderson_Macro.xls!Lee_email_start"Application.Run "Anderson_Macro.xls!Lee_email_start"Application.Run "Anderson_Macro.xls!Mahajan_email_start"Application.Run "Anderson_Macro.xls!Mahajan_email_start"Application.Run "Anderson_Macro.xls!Muqri_email_start"Application.Run "Anderson_Macro.xls!Muqri_email_start"Application.Run "Anderson_Macro.xls!Stamey_email_start"Application.Run "Anderson_Macro.xls!Stamey_email_start"Application.Run "Anderson_Macro.xls!Tucker_email_start"Application.Run "Anderson_Macro.xls!Tucker_email_start"Application.Run "Anderson_Macro.xls!Email_NotEntered1"Application.Run "Anderson_Macro.xls!Email_NotEntered1"End SubEnd Sub

•Since there are a lot of employees that need to be checked. I have set up this master email.

•It launches each macro, one after the other.

Excel MacrosExcel Macros

Sub Workbook_Open()Sub Workbook_Open()Call EmailCall EmailEnd SubEnd Sub

Option ExplicitOption ExplicitSub Email()Sub Email()Application.DisplayAlerts = FalseApplication.DisplayAlerts = FalseApplication.ScreenUpdating = FalseApplication.ScreenUpdating = False On Error Resume Next 'turn error reporting offOn Error Resume Next 'turn error reporting offWorkbooks.Open Filename:="I:\Payroll Histroy\Payroll\ADP User Guides & Paperwork\AN3 Workbooks.Open Filename:="I:\Payroll Histroy\Payroll\ADP User Guides & Paperwork\AN3

NetConsole Reports\Anderson_Macro.xls", Notify:=FalseNetConsole Reports\Anderson_Macro.xls", Notify:=False If ActiveWorkbook.ReadOnly = True ThenIf ActiveWorkbook.ReadOnly = True Then ActiveWorkbook.Close FalseActiveWorkbook.Close False ElseElseApplication.Run "Anderson_Macro.xls!Email_NotEntered"Application.Run "Anderson_Macro.xls!Email_NotEntered"ActiveWindow.CloseActiveWindow.Close End IfEnd If Application.DisplayAlerts = TrueApplication.DisplayAlerts = TrueApplication.ScreenUpdating = TrueApplication.ScreenUpdating = True On Error GoTo 0 'turn error reporting backOn Error GoTo 0 'turn error reporting backThisWorkbook.CloseThisWorkbook.CloseEnd SubEnd Sub

• In order to launch the master macro.

• I create a separate spreadsheet, that has a macro launch upon opening.

• I do this for two reasons:

1. It allows me to create a scheduled task, that open this spreadsheet and then launches the series of macros.

2. It is hard to break into a VBA code, when a query is running. So if I didn’t have a launching macro, it would be hard to update or add new macros.

Scheduled TasksScheduled Tasks

Scheduled TasksScheduled Tasks

• Scheduled Task allows me to set up my macros to run at night.

• Got to

• Start• Settings• Control Panel

Scheduled TasksScheduled Tasks

• Select Scheduled Tasks

Scheduled TasksScheduled Tasks

• Select

• Add Scheduled Task• Next

Scheduled TasksScheduled Tasks

• Select

• Browse

Scheduled TasksScheduled Tasks

• Navigate to your spreadsheet, with the macro that launches upon opening

Scheduled TasksScheduled Tasks

• Select how often you want the process to run.

• This one, I run weekly.

Scheduled TasksScheduled Tasks

• Select

• Time• Day of week

Scheduled TasksScheduled Tasks

• Type in your desktop password and your done. You will have to update all of your tasks, whenever this password changes.

• Your computer needs to be on for these tasks to run.

• I lock my computer, each night.

Scheduled TasksScheduled Tasks• Almost done.

• There is always some weird Microsoft hurdle to jump.

• Whenever you have Excel launch an email, a security warning pops up and you can’t easily code an automatic response.

• Download the software on this site and it always answer yes to those messages.

Making the digital Making the digital certificate/signaturecertificate/signature

Making Digital CertificateMaking Digital Certificate

•One last problem

•When you open a spreadsheet that has a macro. You have to answer enable or disable macro. This can’t be coded either.

•Making a digital certificate solves this last problem.

•Select

•Start•Programs

Making Digital CertificateMaking Digital Certificate•Select

•Microsoft Office•Microsoft Office Tools

Making Digital CertificateMaking Digital Certificate•Select

•Digital Certificate for VBA Projects

Making Digital CertificateMaking Digital Certificate

•Type in a name

•Hit “OK”

Making Digital CertificateMaking Digital Certificate•Your certificate is completed

Applying Certificate to Applying Certificate to VBAVBA

Applying Certificate to VBAApplying Certificate to VBA

•Open up your spreadsheet with the Macro.

•Hold down Alt F11

Applying Certificate to VBAApplying Certificate to VBA

•Select

•Tools•Digital Signatures

Applying Certificate to VBAApplying Certificate to VBA

•Select

•Choose

Applying Certificate to VBAApplying Certificate to VBA•Select

•The certificate you made

•Hit OK

Applying Certificate to VBAApplying Certificate to VBA

•Select

•Save•Close

Applying Certificate to VBAApplying Certificate to VBA

•Select

•Save•Close

Always Trust MeAlways Trust Me

Always trust macro from this publisherAlways trust macro from this publisher•Open spreadsheet(s) again. For a launch spreadsheet, do this at inception of the code and after testing everything (on the master macro).

•Click on check box for “Always trust macros from this publisher”.

•Select Enable Macros.

•When you open this again, there will be no more prompt.

User InstructionsUser Instructions•For the user (if there are any), they need to follow these instructions.

•Users will initially get a grayed out check box.

•They need to select Details

User InstructionsUser Instructions

•Select

•View Certificate

User InstructionsUser Instructions

•Select

•Install Certificate

User InstructionsUser Instructions

•Select

•Next

User InstructionsUser Instructions

•Select

•Next

User InstructionsUser Instructions

•Select

•Finish

User InstructionsUser Instructions•Select

•Yes

User InstructionsUser Instructions

•Select

•OK (on all open screens)

User InstructionsUser Instructions

•Close out of grayed out screen and reopen spreadsheet.

•The user will now have the option to click on the check box.

End ResultEnd Result

End ResultEnd Result

•End result, is that an unwanted (non value added) job is eliminated.

•The possible for error, has now shrunk close to zero.