Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

word autotext incremental date

Status
Not open for further replies.

Kurt111780

Technical User
Nov 20, 2003
235
GB
Hello:

I have a word document that has a table with many rows.

What I need to do:
Starting with the current date, each row needs to go up by one day. Also it needs to skip weekends.

Any ideas on how to do this?

Thank you,
Kurt

It's only easy when you know how.
 
Use an Excel sheet and embed it in the Word document?
 
It can be done in Word. You may have to adjust this for your need, as I don't really know how things are set up in your document. This is based on a bunch of formfields across columns - although that is, actually, irrelevant. It simply take the result of the the previous formfield, as a date, adds a day, checks to see if it is Saturday or Sunday, and adjust accordingly. This is input into the next formfield.
Code:
Sub UpdateOtherDates()
Dim mFF As FormField
Dim i As Integer
Dim dteStart As Date
Dim var As Integer
i = 1
var = 1
On Error Resume Next

For var = 1 To ActiveDocument.FormFields.Count
   Set mFF = ActiveDocument.FormFields(var)
   If var > 1 Then
      dteStart = ActiveDocument.FormFields(var - 1).Result
      Select Case Weekday(dteStart + i)
         Case vbSaturday
            dteStart = dteStart + i + 2
         Case vbSunday
            dteStart = dteStart + i + 1
         Case Else
            dteStart = dteStart + i
      End Select
      ActiveDocument.FormFields(var).Result = dteStart
   End If
   Set mFF = Nothing
Next
End Sub

Gerry
See my Paintings and Sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top