Solved

Need help converting a VBA macro from excel to outlook.

Posted on 2004-03-23
3
323 Views
Last Modified: 2008-02-01
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_End, 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_End, TimeValue(Hour(EndTime) & ":" & Minute(EndTime))) - TimeValue(Hour(WeekDay_Start) & ":" & Minute(SunDay_Start))
End If
....
    tot = tot + totnew * 24
0
Comment
Question by:Gryff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10659671
It appears the Application.Min is the Min function (Min as in MINimum), which returns the smaller of the two values that are the two arguments.

What version of Outlook are you using?

0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 250 total points
ID: 10659703
you may need to write your own Min function:

Public Function Min(byVal Val1 as Date, ByVal Val2 as Date) as Date
   if Val1 < Val2 then
       Min = Val1
   Else
       Min = Val2
End Function

This is assuming that the WeekDay_Start or WeekDay_End variables are Date type values.

can you show the part of your code where the variables WeekDay_Start, WeekDay_End and totnew are DECLARED (Dim totnew as ????)

AW
0
 

Author Comment

by:Gryff
ID: 10667021
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 :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 22 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question