Hello,

Can someone point me in the direction of sample code that will open a
Word document based on date?

We do daily logs and save them in this format:

C:/Logs 05/Jul/Jul23.doc.

So I would love a icon on the desktop called "Open Daily Log" that
opens the log file based on the date.

Thanks in advance.

Brian

Re: Open Word Document Based On Date by Torgeir

Torgeir
Sun Jul 24 13:54:21 CDT 2005

bdaoust@yahoo.com wrote:

> Hello,
>
> Can someone point me in the direction of sample code that will open a
> Word document based on date?
>
> We do daily logs and save them in this format:
>
> C:/Logs 05/Jul/Jul23.doc.
>
> So I would love a icon on the desktop called "Open Daily Log" that
> opens the log file based on the date.
>
> Thanks in advance.
Hi,

Something like this should work:

'--------------------8<----------------------

dDate = Now

sYear = Right(100 + Year(dDate), 2)
sMontName = MonthName(Month(dDate), True)
sDay = Right(100 + Day(dDate), 2)

sFileName = "C:\Logs " & sYear & "\" _
& sMontName & "\" & sMontName & sDay & ".doc"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")

If oFSO.FileExists(sFileName) Then
' Open the file in MS Word
oShell.Run "winword.exe " & sFileName
Else
MsgBox "Non-existing file: " & sFileName, _
vbSystemModal+vbInformation, "Open Daily Log"
End If

'--------------------8<----------------------


WSH 5.6 documentation (local help file) can be downloaded from here
if you haven't got it already:
http://msdn.microsoft.com/downloads/list/webdev.asp


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx