Problem solving using applications by James Tam

Return to the course web page

CPSC 203: Assignment 4 (VBA programming)

Due Friday December 2 at 4 PM

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

For this assignment you are to write VBA macros that will be included in a Word macro-enabled document (ends in the suffix ".docm") document. In order to get credit for the assignment you must write VBA macro code and you will get no credit, for instance, you just take an existing Word document and manually make the changes using Word instead of writing a program. There are a number of sample documents that the TA's 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 there really are macros 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.

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. Word search and replace: The user is prompted for the word to search for and the word to replace it with. The prompts will occur via the InputBox. The program will then search for and replace all instances. If the search word does not exist in the document then nothing will happen. (+0.2 GPA)
  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. 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. No credit will be awarded if the program counts the number of occurrences of the same word each time that it runs. (+0.2 GPA)
  1. Evaluate the quality of the document. (Max of 1.5 GPA). In order to get credit for this feature, Features #3 & #4 must be correctly implemented first. Also the document status (REJECTED, NEUTRAL, SUPERIOR) must appear at the top of the document or you will be awarded no credit for this feature.
 
  • (a) If there are any spelling mistakes in document then the document is automatically rejected (text = "REJECTED") (+0.3 GPA).
 
  • If there are no spelling mistakes then prompt user for a search word via an InputBox (no credit for the features below if search word is the same each time that the program runs.

   
  • (b) If there are zero occurrences of that word then the document is neutral (text = "NEUTRAL"). (+0.3 GPA)
   
  • (c) If there are one or more occurrences of the that word then the document is superior (text = "SUPERIOR"). (+0.3 GPA).
   
  • The quality of the document is not only highlighted by putting the text at the start of the document but visually highlighted:
     
  • (d) bolded font (+0.2 GPA),

     
  • (e) font size of 14 points (+0.2 GPA),

     
  • (f) 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 VBA. (+0.2 GPA)
  1. Close the document and automatically save changes (no choice given to the user). (+0.2 GPA)
  1. Instead of applying Features 1 - 7 on the document in which the macro is contained it will instead it will prompt the user for location to find the documents to be evaluated (e.g., "C:\temp") via a MsgBox and apply Features 1 - 7 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 nested loops in order to get credit for this feature, an outer loop successively opens each document in the specified location and will apply Features 1 - 7 inside its body. (+0.8 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 - 8 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 - 5 features yield 0.1 documentation marks, listing 6 -7 yields  0.2 documentation marks, 8 features yields 0.3 documentation marks. Be sure to document every feature if you don't complete them all.
  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, 8 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 or two instances where named constants could have been employed but you didn't define them then no penalty is applied. If there were three 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").

Submitting your work:

  1. The document must be electronically submitted according to the assignment submission requirements using D2L.

D2L configuration for this course

  • You can (and really should) submit work as many times as you wish before the due date
  • Only your latest submission (what you submitted previously will be overwritten by your latest submission)
  • You can only submit one file per assignment. To  submit multiple files then use 'zip' to contain all the documents in one document: [How to use zip in Windows 7]. Do not use other compression utilities otherwise your submission may not be marked.
  1. You are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the [notes on misconduct for this course].

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. What you have submitted in D2L as of the due date is what will be marked.
  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 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. Method of submission: You are to submit your assignment using D2L [help link]. Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that your submit your assignment with enough time before it comes due for you to do a check).
  4. 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.
  5. Execution: programs must work on the machines in the 203 computer lab. It's up to you to test and check that this is the case. Non-functional submissions will receive only partial credit (if any at all).