Gryff
asked on
Need help converting a VBA macro from excel to outlook.
I have an excel vba/macro that works out how long a particular job takes based on on different working hours and what not. It works great in excel, and being a lazy person I pretty much copied it as is to an outlook macro that has to work out the same information.
However the excel macro refers to 'application.min' which outlook doesn't recognise, additionally I can't actually work out exactly what function 'application.min' has so I could try to make a work around. I would appreciate any suggestions on how to get the current script to work to save me the effort of rebuilding it from scratch.
Here is the part outlook has a problem with.
If i > 0 And i < Int(EndTime) - Int(StartTime) Then
totnew = WeekDay_End - WeekDay_Start
ElseIf i = 0 And WeekDay_End - TimeValue(Hour(StartTime) & ":" & Minute(StartTime)) > 0 And i = (Int(EndTime) - Int(StartTime)) Then
totnew = Application.Min(WeekDay_En d, TimeValue(Hour(EndTime) & ":" & Minute(EndTime))) - TimeValue(Hour(StartTime) & ":" & Minute(StartTime))
ElseIf i = 0 And WeekDay_End - TimeValue(Hour(StartTime) & ":" & Minute(StartTime)) > 0 Then
totnew = WeekDay_End - TimeValue(Hour(StartTime) & ":" & Minute(StartTime))
ElseIf i = (Int(EndTime) - Int(StartTime)) And TimeValue(Hour(EndTime) & ":" & Minute(EndTime)) - WeekDay_Start > 0 Then
totnew = Application.Min(WeekDay_En d, TimeValue(Hour(EndTime) & ":" & Minute(EndTime))) - TimeValue(Hour(WeekDay_Sta rt) & ":" & Minute(SunDay_Start))
End If
....
tot = tot + totnew * 24
However the excel macro refers to 'application.min' which outlook doesn't recognise, additionally I can't actually work out exactly what function 'application.min' has so I could try to make a work around. I would appreciate any suggestions on how to get the current script to work to save me the effort of rebuilding it from scratch.
Here is the part outlook has a problem with.
If i > 0 And i < Int(EndTime) - Int(StartTime) Then
totnew = WeekDay_End - WeekDay_Start
ElseIf i = 0 And WeekDay_End - TimeValue(Hour(StartTime) & ":" & Minute(StartTime)) > 0 And i = (Int(EndTime) - Int(StartTime)) Then
totnew = Application.Min(WeekDay_En
ElseIf i = 0 And WeekDay_End - TimeValue(Hour(StartTime) & ":" & Minute(StartTime)) > 0 Then
totnew = WeekDay_End - TimeValue(Hour(StartTime) & ":" & Minute(StartTime))
ElseIf i = (Int(EndTime) - Int(StartTime)) And TimeValue(Hour(EndTime) & ":" & Minute(EndTime)) - WeekDay_Start > 0 Then
totnew = Application.Min(WeekDay_En
End If
....
tot = tot + totnew * 24
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am using outlook 2000.
Weekday_start and weekday_end are declared as Date Totnew was originially undeclared which should mean that are variants if I am correct. As such I have activated OPTION EXPLICIT and declared them as VARIANT.
I started making some changes based on your comments but found some other areas of the code that are not wroking as expected in outlook 2000 so have decided to write it from scratch myself. This also has the advantage that at least I will understand all of it.
As it turns out my codes is alot shorter as well :)
Thank you for your help and as your answer did tell me what was wrong with the original code snippet I am accepting it as THE answer :)
Weekday_start and weekday_end are declared as Date Totnew was originially undeclared which should mean that are variants if I am correct. As such I have activated OPTION EXPLICIT and declared them as VARIANT.
I started making some changes based on your comments but found some other areas of the code that are not wroking as expected in outlook 2000 so have decided to write it from scratch myself. This also has the advantage that at least I will understand all of it.
As it turns out my codes is alot shorter as well :)
Thank you for your help and as your answer did tell me what was wrong with the original code snippet I am accepting it as THE answer :)
What version of Outlook are you using?