Problem solving using applications by James Tam

Return to the course web page

CPSC 203: Assignment 3 (VBA programming)

Due Friday December 8 at 4 PM

Programming MS-Word using VBA (Visual Basic for Applications):

You will write a VBA macro that will be included in a Word "macro-enabled document" (ends in the suffix ".docm") document. You only need to implement a single macro/sub(routine) in order to get credit, it's not recommended that you implement multiple subroutines. However, in order to get credit for the assignment you must write VBA macro code. You will get no credit, for instance, if you just take an existing Word document and manually edit it yourself. There are a number of sample documents that the TAs may use when marking your work. None of those documents will include things beyond the requirements of the features listed below, they will just evaluate how well you implemented your program. To get you started here is an [example document]. Use this document as a starting point and embed your VBA instructions here (make sure you don't save the VBA macros in "all word documents" but in the sample document. If you are unsure of what this entails then you should refer to your in class lecture notes (the first set of VBA lecture notes) but here is a reminder image of how you should save your macros:

Because your macros will be included in the document, when it comes time to submit your work you can just upload the macro-enabled document. Double check that your VBA macro really is in the Word document that you upload! It is up to you to do the check, you shouldn't rely on us to do it for you.  If you want to be extra safe (and I highly recommend that you do this) you can copy and paste your VBA program into a regular Word document and submit that extra Word document as well the macro-enabled document. As was the case with other assignments do not use other compression utilities (such as zip), otherwise your submission may not be marked.

Similar to the previous assignment everyone starts out with a grade point of zero for this assignment. As you implement the features or documentation requirements listed below your grade will increase. Violating style requirements will result in a decreased assignment grade.

Features that your VBA macros should include:

  1. Style search and replace: The program will search and replace for all instances of the style "Heading 1" with "Normal".  (+0.2 GPA)
  1. Count the number of spelling mistakes in the document. Display the number with a MsgBox. (+0.2 GPA)
  1. Evaluate the quality of the document. (Max of 1.7 GPA). In order to get credit for this feature, Feature #2 must be correctly implemented first. Also the document status (REJECTED, NEUTRAL. SUPERIOR) must clearly appear at the top of the document or you will be awarded reduced credit or even no credit for this feature.
 
  1. If there are any spelling mistakes in document, then the document is automatically rejected (text = "REJECTED" which is written to the top of the document) (+0.3 GPA).
 
  1. If there are no spelling mistakes: The program will count the number of occurrences of a word in the document. The word will be entered by the user as the program runs via an InputBox. The number of occurrences of the word appears in a MsgBox. No credit will be awarded if the program just counts the number of occurrences of the same word each time that it runs (i.e. the user is not prompted for the word). (+0.2 GPA)

   
  1. If there are zero occurrences of that word then the document is neutral (text = "NEUTRAL" which is written to the top of the document). (+0.3 GPA)
   
  1. If there are one or more occurrences of the that word then the document is superior (text = "SUPERIOR" which is written to the top of the document). (+0.3 GPA).
 
  1. The quality of the document (REJECTED, NEUTRAL. SUPERIOR) is not only at the start of the document but it's visually highlighted:
     
  1. bolded font (+0.2 GPA),

     
  1. font size of 14 points (+0.2 GPA),

     
  1. font color of red (+0.2 GPA).

  1. Print the document (you won't actually be able to print anything in the 203 labs because there are no printers connected to the computers) but your program should be able to invoke the print command using the appropriate VBA libary call. (+0.2 GPA)
  1. Close the document and automatically save changes (no choice given to the user/no pop-up prompt appears). (+0.2 GPA)
  1. Instead of applying Features 1 - 5 on just a single document, the macro will instead it will prompt the user for a location (e.g., "C:\temp") via an InputBox and apply Features 1 - 5 to every Word document in that location. When you write the program you can assume that the folder only contains Word documents. You must employ nesting in order to get credit for this feature, an outer loop successively opens each document in the specified location and inside the loop body Features 1 - 5 will be applied. (+1.0 GPA)

Documentation requirements (see Part I of the VBA notes for a detailed explanation for #1 & 2 summary is provided below): documentation marks may be awarded independently of program functionality

  1. Contact information: Name, student ID and tutorial section (+0.1 GPA for including all pieces of information, no credit for partial information)
  2. A list of features (#1 - 6 above) as well as a clear indication if the feature was or was not fully completed and (if applicable) which version of the feature that was completed (0.3 GPA max). Listing 0 - 2 features provides no documentation marks, listing 3 - 4 features yield 0.1 documentation marks, listing 4 - 5 yields  0.2 documentation marks, 6 features yields 0.3 documentation marks. Be sure to document every feature even if you don't complete them all. (Just list each feature and indicate whether or not it was completed).
  3. Use of a versioning system that ties into a list of features completed e.g., "Version (Nov 12) has Feature 1 completed", "Version (Nov 13) Has Features 1, 2, 4 completed" (+0.1 GPA)

Style requirements (see Part I of the VBA notes for a detailed explanation):

Good naming conventions: all program identifiers (variables, named constants, macro and file names must exhibit properties good naming conventions). A penalty of -0.1 GPA will applied for the first instance of a poor naming convention, -0.2 GPA for the second instance down to a maximum penalty of -0.3 GPA for naming conventions.

Appropriate use of named constants. If there is one instance where named constants could have been employed but you didn't define it then no penalty is applied. If there were two or more instances where named constants could have been employed then a maximum penalty of -0.1 GPA will be applied. (To get you started the cut-off used to determine if the number of spelling mistakes is unacceptable is a prime candidate for a named constant e.g. "Const SPELLING_CUTOFF = 0").

Appearance of the VBA instructions. This includes applying proper and consistent indenting (4 spaces for each level of nesting - see the VBA notes Part I). This also includes using white space (spaces, tabs, empty lines) to group related features. In essence this is the 'alignment' and 'proximity' parts of the C.R.A.P. design principles from the end of the notes on spreadsheets. For instance all the instructions associated with Feature #3 should be all grouped together (little or no white space between instructions) and separated from other features using white space. A penalty of -0.1 GPA will applied for the first instance of appearance problems/inconsistencies, -0.2 GPA for the second instance down to a maximum penalty of -0.3 GPA for issues associated with appearance.

Marking:

Important points to keep in mind:

  1. Due time: All assignments are due at 4 PM on the due dates listed on the course web page.  Late assignments or components of assignments will not be accepted for marking without approval for an extension beforehand.
  2. Extensions may be granted for reasonable cases by the course instructor with the receipt of the appropriate documentation (e.g., a doctor's note). Typical examples of reasonable cases for an extension include: illness or a death in the family. Cases where extensions will NOT be granted include situations that are typical of student life: having multiple due dates, work commitments etc. Tutorial instructors (TA's) will not be able to provide extension on their own and must receive written permission from the course instructor first. (Note: Forgetting to hand your assignment or a component of your assignment in does not constitute a sufficient reason for handing your assignment late).
  3. Collaboration: Assignments must reflect individual work, group work is not allowed in this class nor can you copy the work of others. To avoid problems students should not see each others assignment solution.
  4. Execution: programs must work on the machines in the 203 computer lab. It's up to you to test and check this is the case. Non-functional submissions will receive only partial credit (if any at all).