go to & highlight today's date on open

A

adgorn

I have a word document with a lengthy list of dates in a table. Upon
opening, I'd like to see today's date highlighted and have it go to that
date. Help??!! Thanks!
 
H

Helmut Weber

Hi,

in what format are the dates,
and more,
is that format used *consistently* ?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi Alan,

like this:

Sub autoopen()
Dim sTmp As String
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
sTmp = Format(Date, "DD-MMM-YY")
With rDcm.Find
.Text = sTmp
If .Execute Then
rDcm.HighlightColorIndex = wdYellow
rDcm.Select
selection.Collapse
else
Msgbox "date of today not found"
End If
End With
End Sub

Insert a module in the project
with the name of your doc.
Insert the code in that module.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi Alan,

in case you are using the code exactly as it was provided,
add this line before "end sub".

selection.GoTo What:=wdGoToPage, which:=wdGoToNext

Which puts the cursor at the start of the next page,
and to the start of the last page,
if the last date, you've processed, is on the last page anyway.

If there is something wrong, post the exact code you are using.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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