#1
|
|||
|
|||
Add numbers associated with a Style to obtain a total
Hi all,
I'm guessing this won't be possible without VBA (of which I'm relatively new to in Word). I have a Style in my Word docs that consist of a slash and a number (e.g. /5). The number is the mark associated with each question in a Knowledge Test (Assessment). Yes, I'm a teacher. I'm hoping there's an easy way to add up all of the marks in the document and have a total shown on the front page without having to manually add the marks each time an assessment is created. Thanks in advance. |
#2
|
||||
|
||||
It would help if you posted a link to an example document.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
I think this is requires VBA and I would do it with Content Controls so you can store sectional scores and possible marks and total both at the top of the document.
I've created a demonstration of this method with some Content Controls for each area where you want to assign a score. I've used the Title and Tag settings to allow the macro to make the decisions. The code is in the ThisDocument module. Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean) Dim iTally As Double, iScore As Double, iMax As Double, iResp As Integer, aCCsect As ContentControl Dim arrMark() As String, iMark As Double Select Case aCC.Title Case "Overall Mark" If aCC.ShowingPlaceholderText Or aCC.Range.Text Like "0*" Then iResp = MsgBox("Do you want to reset/clear all marks from this document?", vbYesNo + vbCritical, "Clear All") If iResp = vbYes Then For Each aCCsect In ActiveDocument.SelectContentControlsByTitle("Section Mark") iMax = iMax + aCCsect.Tag aCCsect.Range.Text = "" Next aCCsect aCC.SetPlaceholderText Text:="Test is marked out of " & iMax End If End If Case "Section Mark" aCC.SetPlaceholderText Text:="This section is worth " & aCC.Tag For Each aCCsect In ActiveDocument.SelectContentControlsByTitle("Section Mark") iMax = iMax + aCCsect.Tag If Not aCCsect.ShowingPlaceholderText Then arrMark = Split(aCCsect.Range.Text, " / ") iMark = arrMark(0) aCCsect.Range.Text = iMark & " / " & aCCsect.Tag iScore = iScore + iMark End If Next aCCsect With ActiveDocument.SelectContentControlsByTitle("Overall Mark")(1) .LockContents = False If iScore > 0 Then .Range.Text = iScore & " / " & iMax Else .Range.Text = "" 'show placeholder text End If .LockContents = True End With End Select End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#4
|
||||
|
||||
Andrew
I would agree with that approach if starting anew, but from the OP's comments I suspect the documents are already prepared and scored, which is why I suggested posting a sample, to ensure that we are on the same page when it comes to handling those documents. I suppose we will have to wait for a follow-up.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Section Number with Total Page Numbers | CobraLAD | Word | 2 | 07-07-2021 11:09 AM |
Help to use VBScript to total numbers from multiple tables | tms_admin | Word VBA | 2 | 11-07-2018 10:56 PM |
Inventory-Trying to add numbers to a total based on the numbers above. | beeker223 | Excel | 13 | 07-17-2017 11:12 AM |
How to obtain a column total using only specific cells | Jo Freeman | Excel | 3 | 03-20-2015 06:18 AM |
How obtain accurate total of hours estimated of all subtasks that are a certain type? | pcumming | Project | 3 | 05-14-2014 05:45 PM |