Problem solving using applications by James Tam

Return to the course web page

CPSC 203: Assignment 3 (VBA programming)

Due Tuesday March 24 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. You will get no credit if for instance you just take an existing Word document and manually make the changes using Word instead of writing a VBA 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 very first VBA lecture) but here is a reminder image of how you should save your work:

Because your macros will be included in the document when it comes time to submit your work you can 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 recommend this) you can copy and paste your VBA program into a regular Word document and submit that extra word document as well.

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 program will then search for and replace all instances. If the search word does not exist in the document then nothing will happen.
  1. Style search and replace: The program will search and replace for all instances of the style "Heading 1" with "Normal"
  1. Alphabetically sort table the contents of a table in ascending order ('a' to 'z'): you will get credit for implementing one of the following versions of this feature. In both cases the program only has to sort the contents within each table but not between tables (e.g., the first entry of the second table can come alphabetically before the last entry of the first table).
 
  • Basic version: Your program is written so it can sort a fixed number of tables only e.g., my sample document only contains two tables: 'martial arts' and 'video games'.
 
  • Advanced version: Your program can sort a document with any number of tables. If there are no tables in a document then the program should display some sort of meaningful error message to the user.
  1. Run a spell check of the document.
  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.
  1. Save the document (your program doesn't have to check if any changes were actually made to the document it just has to allow the user the option of saving the document).
  1. Close the document.

In addition being marked on the above features it will also  be marked according to how well it conforms to the style and documentation requirements taught in lecture. If you want to what the sample documents appears like after the macros have been run this is the "after version of the document" (macros removed of course).

Submitting your work:

  1. Assignments (the macro-enabled "doc-m" file) must be electronically submitted according to the assignment submission requirements using D2L.
  2. 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].
  3. Before you submit your assignment here is a [checklist] of items to be used in marking.