title: How to round time to the nearest quarter hour in word
body: <p>I need to round time to the nearest quarter hour in a word document.  I am not very good at coding.</p>
  <p>After a fair bit of searching I have found some vba code but it doesn't quite work.  The code is:</p>
  <pre><code>Sub Time()
  Dim num() As String
  Dim tod() As String
  Dim temp As String
  
  num = Split(Time, &quot;:&quot;)
  tod = Split(num(2), &quot; &quot;)
  
  If Val(num(1)) &lt; 15 Then
      temp = &quot;00&quot;
  ElseIf Val(num(1)) &lt; 30 Then
      temp = &quot;15&quot;
  ElseIf Val(num(1)) &lt; 45 Then
      temp = &quot;30&quot;
  ElseIf Val(num(1)) &lt; 60 Then
      temp = &quot;45&quot;
  End If
  gettime = num(0) + &quot;:&quot; + temp + &quot;:00 &quot; + tod(1)
  
  End Function
  End Sub
  </code></pre>
  <p>When I try to run it I get a message:</p>
  <blockquote>
  <p>&quot;Compile Error: Expected function or variable&quot;</p>
  </blockquote>
  <p>and &quot;Time&quot; on the fifth line of the code is highlighted which I think is where the program stops running.</p>
  <p>The rest of the code in the form is as follows:</p>
  <p><strong>This module doesn't affect the time rounding issue but I am including it so as not to leave anything out.</strong></p>
  <pre><code>Option Explicit
  
  Sub ClusterCheck()
  
  Dim i As Integer, k As Integer, iCluster As Integer, bResult As Boolean
  Dim sFieldNameNo As String, sName As String
  
      On Error Resume Next    ' If the first formfield is a checkbox, this will bypass the error that Word returns
      
      sName = Selection.FormFields(1).Name    ' Get the name of the formfield
      bResult = ActiveDocument.FormFields(sName).CheckBox.Value    ' Get the result of the current formfield
      sFieldNameNo = Number(sName)    ' Get generic number
      sName = Left(sName, Len(sName) - Len(sFieldNameNo))    ' Get generic name
      
      ' Determine how many fields are within the cluster group
      iCluster = 1
      Do Until ActiveDocument.Bookmarks.Exists(sName &amp; iCluster) = False
          iCluster = iCluster + 1
      Loop
      iCluster = iCluster - 1
      
      ' If the check field is true, turn all of the other check fields to false
      Application.ScreenUpdating = False
      If bResult = True Then
          For k = 1 To iCluster
              If k &lt;&gt; sFieldNameNo Then ActiveDocument.FormFields(sName &amp; k).Result = False
          Next
      End If
      Application.ScreenUpdating = True
      
  End Sub
  </code></pre>
  <p><strong>This is the Number module:</strong></p>
  <pre><code>Option Explicit
  
  Function Number(ByVal sNumber As String) As String
  
  ' This module finds the form fields number within the field name
  
      ' Loops through the field name until it only has the number
      Do Until IsNumeric(sNumber) = True Or sNumber = &quot;&quot;
          sNumber = Right(sNumber, Len(sNumber) - 1)
      Loop
      
      Number = sNumber
  
  End Function
  </code></pre>
  <p><strong>This is the protection module:</strong></p>
  <pre><code>Option Explicit
  
  Sub Protect()
  
      ActiveDocument.Protect Password:=&quot;wup13&quot;, NoReset:=True, Type:=wdAllowOnlyFormFields
  End Sub
  
  Sub Unprotect()
  
      ActiveDocument.Unprotect Password:=&quot;wup13&quot;
  End Sub
  </code></pre>
  <p><strong>This is the code that activates on opening and closing the document:</strong></p>
  <pre><code>Option Explicit
  
  Sub Document_Open()
  
      ' Zooms to page width, turns on Hidden Text, and turns off ShowAll and Table Gridlines
      With ActiveWindow.View
          .Zoom.PageFit = wdPageFitBestFit
          .ShowHiddenText = True
          .TableGridlines = False
          .ShowAll = False
      End With
      
      Options.UpdateFieldsAtPrint = False
  
  End Sub
  
  Sub Document_Close()
  
      ' Turn on ShowAll and Table Gridlines
      With ActiveWindow.View
          .ShowAll = True
          .TableGridlines = True
      End With
      
      Options.UpdateFieldsAtPrint = True
      
  End Sub
  </code></pre>
  <p>That's all the code in the form. I am not great at VBA but am hoping I can solve this issue (with a little help).</p>
  <p>DETAILS OF EXTRA DUTY FORM</p>
  <p>Persons details
  Family name:<br />
  Given name(s):</p>
  <p>Level:<br />
  No.:<br />
  Location:</p>
  <p>Cost Centre Code:</p>
  <p>Time worked
  Were any days of the extra duty performed on a designated public/show holiday?  Yes  0  No  0
  If yes enter holiday date/details:</p>
  <p>Time commenced: [Text Form Field]<br />
  Date:</p>
  <p>Time ceased:    [Text Form Field]<br />
  Date:</p>
  <p>Total Overtime claimed:</p>
  <p>Are you a shift worker? Yes  0     No  0</p>
  <p>Details of extra duty performed:</p>
  <p>Vehicle details
  Car:  Yes  0     No  0
  Motorcycle:  Yes  0     No  0
  Registration no.:<br />
  Fleet no.:</p>
  <p>Stationary vehicle hours:<br />
  Yes  0     No  0  (only use for stationary duties)</p>
  <p>Vehicle odometer start:<br />
  Odometer finish:<br />
  Total kms:</p>
  <p>Client’s details
  Company/Organisation name:<br />
  Phone no.:</p>
  <p>Contact name:</p>
  <p>Job no.:</p>
  <p>Payment for special services
  Was payment received in advance?    Yes  0      No  0</p>
  <p>If Yes– Amount:<br />
  Receipt no.:<br />
  Date:</p>
  <p>If No–  Amount:<br />
  Invoice no.:<br />
  Date:</p>
  <p>I,            , certify the above information to be true</p>
  <p>(Signature)     (Date)<br />
  Manager certification (Checked with roster and certified correct)</p>
  <p>(Signature)     (Date)</p>