Hi everyone,
I have a daily activity table with start and end times. The end time of each activity must end 1 minute before the next event starts. The document is content control and it cannot have overlapping times. Below is a example:
[TABLE="width: 482"]
00:00
01:21
First event happened.
01:22
02:27
Next event happened.
[/TABLE]
I am trying to figure out how to write a macro to automatically fill in the end times which is always 1 minute from the start time of the next event.
So far I figured out the table id, which is table 2. The .title tag which is "Start Time (hh:mm)" and the .title tag for the end time "End Time (hh:mm)"
I am stuck and would greatly appreciate any help. I can do it the very crude way but there has to be a more efficient way. Attached is the code and the content control document.
' Subtract1Minute for the end time Macro
'
'
Set Daily_Events = ActiveDocument
Daily_Events.Activate
Set tgtDoc = Daily_Events
Set tgtTable = tgtDoc.Tables(2)
'Trying to use the date function
For i = 3 To tgtTable.Rows.Count
Set date1 = tgtTable.Cell(i, 1)
Set date2 = tgtTable.Cell(i, 2)
Next i
'Trying to use the .title tag
With ContentControl
If .Title = "Start Time (hh:mm)" Then
If tgtTable.Cell(i, 1).Range.ContentControls(1).Range.Text = date1 Then
'Trying to subtract using date
For J = 3 To tgtTable.Rows.Count
If tgtTable.Cell(i, 1).Range.ContentControls(1).Range.Text = date1 Then
tgtTable.Cell(i, 2).Range.ContentControls(1).Range.Text = date2 - date1
End If
Next J
'#######################################################
' CRUDE WAY
'#######################################################
'For i = 3 To tgtTable.Rows.Count
' If tgtTable.Cell(i, 1).Range.ContentControls(1).Range.Text = "00:00" Then
' tgtTable.Cell(i, 2).Range.ContentControls(1).Range.Text = "00:01"
' Else
' If tgtTable.Cell(i, 1).Range.ContentControls(1).Range.Text = "00:01" Then
' tgtTable.Cell(i, 2).Range.ContentControls(1).Range.Text = "00:02"
' End If
' End If
' Next
End Sub
Display More