Open Calendar to Specific Date

B

Ben

I have a weekly calendar (one week per page) in Word 2007. When Word opens,
it automatically opens to the first page. How do I program Word so that it
opens to the current date/week (i.e. to the page with the week beginning June
14, 2009)?
 
J

Jay Freedman

I have a weekly calendar (one week per page) in Word 2007. When Word opens,
it automatically opens to the first page. How do I program Word so that it
opens to the current date/week (i.e. to the page with the week beginning June
14, 2009)?

That depends on whether the specific date is somewhere on that page, and in what
format. The general idea is that you create a macro named AutoOpen (which runs
automatically when the document opens), in which the macro does a Find for the
date of the first day of the current week.

If your dates are in the format you showed above, and if each page starts with
Sunday's date, then the following macro will go to the beginning of the page
that contains the current date (see http://www.gmayor.com/installing_macro.htm
if needed).

Sub AutoOpen()
Dim startThisWeek As Date
Dim searchTerm As String
Dim rg As Range

startThisWeek = Now
While Not Weekday(startThisWeek) = vbSunday
startThisWeek = DateAdd("d", -1, startThisWeek)
Wend

searchTerm = Format(startThisWeek, "MMMM d, yyyy")

Set rg = ActiveDocument.Range
With rg.Find
.Text = searchTerm
If .Execute Then
rg.Select
End If
End With
End Sub

If you would rather go to the current date no matter where it is on the page,
remove the three lines from "While" to "Wend".
 
B

Ben

Thanks Jay. This worked great. I just had to change the date format because
it was different from what I originally wrote.
 

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