T
Tony WONG
i run this script daily to generate html file for records from today to end
of the month but find this script use a lot of resources to loop through all
the items in "" For each Item in KKK ..... Next" loop.
it seems logical to do it but it needs a few minutes to complete.
if i do it by outlook (save as web page), it just a few seconds. the
performance is much better by my script.
Could you kindly comment my script whether it is somehow excessive?
the folder has 2xxx record items. any ways to do it better and faster.
Thanks a lot.
tony
******************** VB script ****************************
Set fso = CreateObject("Scripting.FileSystemObject")
Set webfile = fso.CreateTextFile("c:\temp\uploadevent.htm", True)
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOLApp.GetNamespace("MAPI")
Set ABC = myNamespace.GetDefaultFolder(18)
For Each objfolder In ABC.Folders
If objfolder = "Event" Then
Set KKK = objfolder.Items
KKK.Sort "Start", False
date1 = DateAdd("m", 1, Date)
date2 = Year(date1) & "/" & Month(date1) & "/" & "1"
date3 = FormatDateTime(date2)
date4 = DateAdd("d", -1, date3) + 0.99999
b = 0
webfile.Write "<html><head><META HTTP-EQUIV='Content-Type'
content='text/html; charset=big5'><link rel=stylesheet href=schedule.css
type=text/css></head><body bgcolor ='#CCFFFF'>"
For Each Item In KKK
If Item.Class = 26 Then
If Item.Start >= date + 0.00001 And Item.Start <= date4 Or
Item.Start < date4 And Item.end > date4 Or Item.End >= date + 0.00001 And
Item.End <= date4 + 0.00001 Then
With webfile
If DateValue(Item.Start) <> a Then
If b <> 0 Then
.writeline "<br>"
End If
b = b + 1
if DateValue(Item.Start) < DateValue(date) then
mark = DatePart("yyyy", Item.Start) & DatePart("m", Item.Start) &
DatePart("d", Item.Start)
else
mark = "mark"
end if
.writeline "<a name=" & mark & " id=" &
mark & " href='#" & mark & "'>" & day(item.start) & " " &
MonthName(month(item.start), true) & " - " &
weekdayname(weekday(item.start)) & "</a><br>"
End If
.write "<strong>" & Item.Subject &
"</strong>"
If Item.Location <> "" Then
itemLocat = " (" & Item.Location & ")"
End If
If Item.End - Item.Start < 1 Then
.Write "    " &
Left(TimeValue(Item.Start), 5) & " - " & Left(TimeValue(Item.End), 5)
ElseIf Item.End - Item.Start = 1 Then
.Write "    " & "Full day"
ElseIf Item.End - Item.Start > 1 Then
if MonthName(Month(Item.Start), True) = MonthName(Month(Item.End -
0.00001), True) then
.Write "    " &
Right(FormatDateTime(DateValue(Item.Start), 2), 2) & " - " &
Right(FormatDateTime(DateValue(Item.End) - 1, 2), 2) & " " &
MonthName(Month(Item.Start), True)
else
.Write "    " &
Right(FormatDateTime(DateValue(Item.Start), 2), 2) &
MonthName(Month(Item.Start), True) & " - " &
Right(FormatDateTime(DateValue(Item.End) - 1, 2), 2) & " " &
MonthName(Month(Item.End), True)
end if
End If
.writeline itemLocat & "<br>"
itemLocat = ""
End With
a = DateValue(Item.Start)
End If
End If
Next
webfile.Write "</body></html>"
webfile.Close
End If
Next
of the month but find this script use a lot of resources to loop through all
the items in "" For each Item in KKK ..... Next" loop.
it seems logical to do it but it needs a few minutes to complete.
if i do it by outlook (save as web page), it just a few seconds. the
performance is much better by my script.
Could you kindly comment my script whether it is somehow excessive?
the folder has 2xxx record items. any ways to do it better and faster.
Thanks a lot.
tony
******************** VB script ****************************
Set fso = CreateObject("Scripting.FileSystemObject")
Set webfile = fso.CreateTextFile("c:\temp\uploadevent.htm", True)
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOLApp.GetNamespace("MAPI")
Set ABC = myNamespace.GetDefaultFolder(18)
For Each objfolder In ABC.Folders
If objfolder = "Event" Then
Set KKK = objfolder.Items
KKK.Sort "Start", False
date1 = DateAdd("m", 1, Date)
date2 = Year(date1) & "/" & Month(date1) & "/" & "1"
date3 = FormatDateTime(date2)
date4 = DateAdd("d", -1, date3) + 0.99999
b = 0
webfile.Write "<html><head><META HTTP-EQUIV='Content-Type'
content='text/html; charset=big5'><link rel=stylesheet href=schedule.css
type=text/css></head><body bgcolor ='#CCFFFF'>"
For Each Item In KKK
If Item.Class = 26 Then
If Item.Start >= date + 0.00001 And Item.Start <= date4 Or
Item.Start < date4 And Item.end > date4 Or Item.End >= date + 0.00001 And
Item.End <= date4 + 0.00001 Then
With webfile
If DateValue(Item.Start) <> a Then
If b <> 0 Then
.writeline "<br>"
End If
b = b + 1
if DateValue(Item.Start) < DateValue(date) then
mark = DatePart("yyyy", Item.Start) & DatePart("m", Item.Start) &
DatePart("d", Item.Start)
else
mark = "mark"
end if
.writeline "<a name=" & mark & " id=" &
mark & " href='#" & mark & "'>" & day(item.start) & " " &
MonthName(month(item.start), true) & " - " &
weekdayname(weekday(item.start)) & "</a><br>"
End If
.write "<strong>" & Item.Subject &
"</strong>"
If Item.Location <> "" Then
itemLocat = " (" & Item.Location & ")"
End If
If Item.End - Item.Start < 1 Then
.Write "    " &
Left(TimeValue(Item.Start), 5) & " - " & Left(TimeValue(Item.End), 5)
ElseIf Item.End - Item.Start = 1 Then
.Write "    " & "Full day"
ElseIf Item.End - Item.Start > 1 Then
if MonthName(Month(Item.Start), True) = MonthName(Month(Item.End -
0.00001), True) then
.Write "    " &
Right(FormatDateTime(DateValue(Item.Start), 2), 2) & " - " &
Right(FormatDateTime(DateValue(Item.End) - 1, 2), 2) & " " &
MonthName(Month(Item.Start), True)
else
.Write "    " &
Right(FormatDateTime(DateValue(Item.Start), 2), 2) &
MonthName(Month(Item.Start), True) & " - " &
Right(FormatDateTime(DateValue(Item.End) - 1, 2), 2) & " " &
MonthName(Month(Item.End), True)
end if
End If
.writeline itemLocat & "<br>"
itemLocat = ""
End With
a = DateValue(Item.Start)
End If
End If
Next
webfile.Write "</body></html>"
webfile.Close
End If
Next