Share via

Parse Word Document

Anonymous
2021-02-09T17:04:30+00:00

I am trying to prevent cheating in an Exam. This is MS Word where students will change fonts styles etc. My plan is to give each student - say 500 an unique exam with specific instructions. Rather than having to mark each paper, is there a way to extract the source code of the Word Document and parse it to find specific properties?

This way, I can compare the expected result with the actual and mark the exams automatically.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323K Reputation points MVP Volunteer Moderator
    2021-02-10T06:05:14+00:00

    If you change the extension of a Word (.docx) file to .zip you can extract the components of the document from the archive and in the word folder in the archive, there is document.xml file that contains the text of the document as well as a whole raft of other details.

    I am not sure that accessing it is going to make the task of marking any simpler.

    Was this answer helpful?

    4 people found this answer helpful.
    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2021-02-10T08:13:32+00:00

    Using either the original document or a document answered as it should be as a base, you can use Word's document comparison tool to identify any differences between it and the submitted one. The following macro will expedite the process. Simply add the macro to the base document, then run the macro. All you need do is select the folder containing the files to be marked. The output files (with the 'Marked' suffix) will mark any differences between the base document and the comparison documents as tracked changes.

    Sub MarkDocuments()

    Application.ScreenUpdating = False

    Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document

    Set wdDoc = ActiveDocument: strDocNm = wdDoc.FullName

    strFolder = GetFolder

    If strFolder = "" Then Exit Sub

    strFile = Dir(strFolder & "\*.doc", vbNormal)

    Do While strFile <> ""

      If strFolder & "" & strFile <> strDocNm Then

        wdDoc.Merge FileName:=strFolder & "" & strFile, MergeTarget:=wdMergeTargetNew, _

        DetectFormatChanges:=True, UseFormattingFrom:=wdFormattingFromCurrent, AddToRecentFiles:=False

        With ActiveDocument

          .SaveAs FileName:=strFolder & "" & Split(strFile, ".doc")(0) & " - Marked.docx", _

            FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False

          .Close False

        End With

      End If

      strFile = Dir()

    Loop

    Set wdDoc = Nothing

    Application.ScreenUpdating = True

    End Sub

    Function GetFolder() As String

    Dim oFolder As Object

    GetFolder = ""

    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)

    If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path

    Set oFolder = Nothing

    End Function

    For PC macro installation & usage instructions, see: Installing Macros (gmayor.com)

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments