How do you link VB code to a table field?

M

Michaelcip

Using Word 2093. I have code, now I need it to place it into the table cell
so that it'll perform the code. Familiar w/ Access VBA, but discovered that
word is different. When the form opens the date of the ending Sunday will
populate into a cell (for time card form). Thanks, MC
 
G

Graham Mayor

The macro will have to be triggered by some means. See the previous thread
and please keep to the one thread.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Doug Robbins - Word MVP

So what you have is a seven column table and in the first row of the table,
you want to put the days/dates of the week (which week, current week or next
week?) with Monday in the first column and Sunday in the last.

The following macro will do that, asking you if you want the dates for the
current week or the next week

Dim lag As Long
Dim Response
Select Case Format(Date, "ddd")
Case "Sun"
lag = 1
Case "Sat"
lag = 2
Case "Fri"
lag = 3
Case "Thu"
lag = 4
Case "Wed"
lag = 5
Case "Tue"
lag = 6
Case Else
lag = 0
End Select
Response = MsgBox("Do you want the dates for this week? Click Yes for this
week, No for next week.", vbYesNo + vbQuestion)
If Response = vbYes Then
lag = lag - 7
Else
lag = lag
End If
With ActiveDocument.Tables(1)
For i = 1 To 7
.Cell(1, i).Range.Text = Format(DateAdd("d", lag + i - 1, Date),
"dddd, dd/mm/yyyy")
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top