Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-30-2022, 08:53 PM
sw-777 sw-777 is offline Add numbers associated with a Style to obtain a total Windows 10 Add numbers associated with a Style to obtain a total Office 2021
Novice
Add numbers associated with a Style to obtain a total
 
Join Date: Oct 2022
Posts: 1
sw-777 is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 10-31-2022, 02:51 AM
gmayor's Avatar
gmayor gmayor is offline Add numbers associated with a Style to obtain a total Windows 10 Add numbers associated with a Style to obtain a total Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 10-31-2022, 10:11 PM
Guessed's Avatar
Guessed Guessed is offline Add numbers associated with a Style to obtain a total Windows 10 Add numbers associated with a Style to obtain a total Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Attached Files
File Type: docm Demonstration_TestScores.docm (36.1 KB, 2 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 11-01-2022, 12:52 AM
gmayor's Avatar
gmayor gmayor is offline Add numbers associated with a Style to obtain a total Windows 10 Add numbers associated with a Style to obtain a total Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add numbers associated with a Style to obtain a total Section Number with Total Page Numbers CobraLAD Word 2 07-07-2021 11:09 AM
Add numbers associated with a Style to obtain a total Help to use VBScript to total numbers from multiple tables tms_admin Word VBA 2 11-07-2018 10:56 PM
Add numbers associated with a Style to obtain a total Inventory-Trying to add numbers to a total based on the numbers above. beeker223 Excel 13 07-17-2017 11:12 AM
Add numbers associated with a Style to obtain a total How to obtain a column total using only specific cells Jo Freeman Excel 3 03-20-2015 06:18 AM
Add numbers associated with a Style to obtain a total How obtain accurate total of hours estimated of all subtasks that are a certain type? pcumming Project 3 05-14-2014 05:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft