Excel Reports and Macros Within Microsoft Excel it is possible to create a macro. This is a set of commands that Excel follows to automatically make certain changes to data in a spreadsheet. By adding a macro to an Excel report in SIMS.net, when a report is run, Excel will automatically make any required changes to the data such as formatting cells and creating graphs. This saves you carrying out the lengthy task of making such changes yourself, each time the report is run. The following describes how to create such a macro and add it to a SIMS.net Excel report. Creating a copy of the ReportData Worksheet When Excel reports are run in SIMS.net, a template called ReportData.xls is used by Excel to present the data in a suitable format. In the following example we shall create a macro, a set of instructions, telling Excel how to format the data further. We must insert our macro into this ReportData.xls template so that when the report is run, Excel will use our version of the template, applying the formatting we have specified. In that case we must first create a copy of the ReportData.xls template so that we can save this as our version, leaving the original intact to run with other Excel reports. Right-click on the Windows Start button and select Explore.
The ReportData Worksheet is saved within the TempSimsRpt folder. This can usually be found in your My Documents folder. Navigate to: My Documents\TempSimsRpt. Once located, right-click on the ReportData file and select Copy. Navigate to your Desktop and once there, right-click and select Paste.
A copy of the ReportData file will be copied to the Desktop. This file will be used later once our macro has been created. Creating the Excel Report Select Reports Design Report. Click on Create a new report. Select Student as the Data Area for your report. Click Next>>. Select student On roll. Click Next>>.
Select the following Data fields: Name & Reg Select the Attendance Marks related field. Do not add any fields to this sub-report. Leave it so that Count is displayed. Click the Red Book icon. Add the following filter: Mark, is one of, Present (AM) And Present (PM). Click OK.
Click AND and add a second filter: Mark date is between prompt at runtime. In this way the report will count how many present marks have been recorded for each student between the specified dates. To identify that this column is counting the number of present marks highlight the Attendance marks related field so that Count is displayed in the Caption field. Overtype this to display Present.
We can now add similar columns that will count other types of marks e.g. Lates. Highlight the Attendance marks sub report and click the Duplicate button to the right of the screen. A copy of the sub report is created. The filters added to the original sub report are also copied. With the copied sub report highlighted, if not already displayed, click the Red Book icon to show the filters.
Highlight the Mark is filter and click Modify. Remove the ticks from the present marks and tick L Late (before registers closed) instead. Click OK. This column will now count the number of lates between the specified dates.
With the second sub report highlighted, overtype the description in the Caption field with Lates. Repeat the same process to create a sub report for possible attendances. When editing the filter, ensure that all the mark types are selected except #, Y, X, Z and @. You should now have three sub reports listed, each counting the number of different types of attendance marks. Click Next>>.
Add a filter so that you can select particular registration groups. Click Next until you reach the Define Presentations screen. Select the output type as Excel. Ensure that Divider Frequency is set to 0 and Go straight to Print Preview is unticked. Run the report. You will be asked to enter the mark dates three times (one for each type of mark being counted). Ensure that the same dates are selected for each. Select a reg group. Click OK.
Excel opens. Should the following Security Warning be displayed, saying Macros have been disabled, click Enable Content. Click OK. The number of present, late and possible marks is displayed. We shall add a formula to calculate percentage attendance and percentage lates. As we do this, we can record the steps being taken to carry out this procedure to create a set of commands known as a macro. This set of commands can then be played back by Excel next time the report is run and the same procedure will be carried out on the data automatically.
Click onto the View tab. Click onto the drop-down arrow on the Macros button and select Record Macro. In the Record Macro box enter Highlight as the Macro Name. Click OK. Any actions performed from now on in Excel will be translated into the set of commands making up the macro until you tell Excel to stop recording. Excel often interprets the numbers from SIMS.net as text, so we first need to convert these to number format. This can be seen by green triangles in the corner of the cells. In cell H1 type the number 1 and press Enter. Click cell H1 again then click onto the Home tab and click the Copy button to copy the contents of H1.
Now highlight cell A1 and, still on the Home tab, click on the Find & Select button and select Go To Special. Select Current Region. Click OK. The data is highlighted. By highlighting the data in this way, if the report is run later using the macro and there were more rows in the report, the additional rows will still be highlighted. Had we just highlighted what was in the report this time, when the report is run later, additional rows would be missed and the formatting would not be applied to that data. Still on the Home tab, click on the drop-down arrow on the Paste button and select Paste Special.
Select Multiply. Click OK. Text values now become numbers the green triangles are removed. Next it is necessary to add additional column headings for Present + Late and % Attendance. In the first row of the Present + Late column enter the formula =B2 + C2. Click Enter.
In the % Attendance column enter the formula =E2/D2. Click Enter. Highlight the cells containing the formula and drag down to fill down the remaining rows with these formulae. Fill down the formulae further than the number of rows for which you currently have data - the maximum number of rows you are likely to have in your report e.g. 300.
0 and #DIV/0! Will be displayed against those rows where there is not currently any data. Highlight the % Attendance column, then right-click and select Format Cells.
Select Percentage and 2 Decimal Places. Click OK. The values are now shown as percentages.
To hide the 0 and #DIV/0!, select all the columns then on the Home tab, click the Sort & Filter button then select Filter. Click on the down arrow within the % Attendance column and select Number filters Does Not Equal.
Select =DIV/0! From the drop-down list of values. Click OK. Rows with no values are now hidden. The relevant changes have now been made in Excel. On the View tab click the Macros button and select Stop Recording. Our actions in Excel have now been recorded and converted into a set of commands. We must make a copy of these commands and insert them into the copy of the ReportData file we made earlier. Click the drop-down arrow on the Macros button again and this time select View Macros.
Select the Highlight macro and click the Edit button. The Microsoft Visual Basic Editor opens displaying a set of commands corresponding to our actions in Excel. This is the macro.
Highlight all of the macro and select Edit Copy. Select File Close and Return to Microsoft Excel to exit the Microsoft Visual Basic Editor. Close Excel and choose No to saving the changes. Minimise SIMS.net so that you can see the Desktop. Open the copy of the ReportData file you saved on your Desktop. Excel opens. Should the following Security Warning be displayed, saying Macros have been disabled, click Enable Content. Click OK. Should the following error message be displayed, click OK to continue.
Click onto the View tab, then click the dropdown arrow on the Macros button and select View Macros. Highlight the Auto_Open macro. Auto_Open is another macro or set of commands that Excel follows when reports from SIMS.net are opened in Excel. We are going to add the extra commands from our Attendance macro to this standard one so that Excel will follow these as well next time a SIMS.net report opens in Excel. Click the Edit button. Once again the Microsoft Visual Basic Editor opens, this time displaying the Auto_Open macro commands. Scroll down to the bottom of the Auto_Open macro and position the cursor below the last line of code. Select Edit Paste to paste the Attendance macro code into the Auto_Open macro.
It is now necessary to tell the Auto_Open macro to look for the commands in our Attendance macro. Scroll back up to a place about a third of the way down the code and find the line that says FixAddressColumn. Immediately below this line enter the name of your macro, in this case Attendance. Select File Save ReportData.xls Should the following message be displayed select Save changes and discard signature. Select File Close and Return to Microsoft Excel to exit the Microsoft Visual Basic Editor. In Excel select File Exit.
Attaching the new ReportData file to your Excel Report We must now tell SIMS.net to look at the new version of the ReportData file containing our macro when it runs the Excel report, rather than the original version. Return to the Define Presentations screen of the report design back in SIMS.net. In Excel Settings area select Report Template. Navigate to the ReportData file saved to the Desktop earlier. Highlight the file and click Open.
You should now save your report design with the new version of the ReportData file attached. Select Save As and name the report Percentage Attendance. Click Run. Select the relevant dates and reg groups. Excel opens. Once you are happy with your output, delete the copy of ReportData from the Desktop as this will not be needed again. SIMS.net keeps its own copy saved with the report design in the document server.