max function in VBA?

Started by orange12, October 03, 2017, 08:14:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

orange12

Hello, I'm trying to find the maximum of three numbers in a VBA script but I'm not quite sure how to import the MAX() function that could be called in a ShapeSheet cell. My search has only turned up a result for Excel VBA where Max is a method of the WorksheetFunction object.

MyValue = Application.WorksheetFunction.Max()

Is there a Visio equivalent to this?

Thanks.

Surrogate

#1
Visio haven't built-in MAX() function in VBA environment!
Quote from: NARKIVE: MIN, MAX functions?Q: Hello,
how can I use the MIN, MAX functions which the online help happily suggests
me to use, however when I try to do so I get the 'sub or function not
defined'. Do I need to add a reference to some 'math' module??


A: The MIN and MAX functions are shapesheet functions that you can put in
cell formulae.
You'll have to write your own VBA functions.


Also you can use MS Excel application as object in MS Visio, for calculate MAX function
Sub n()
Dim c(3) As Single ' array with compared values
c(1) = 1
c(2) = 3
c(3) = 2
Dim ex As Object ' excel application object
Set ex = CreateObject("Excel.application")
Dim r As Single
r = ex.WorksheetFunction.Max(c())
Set ex = Nothing
End Sub

metuemre

The other way would be to put the numbers in an array, sort the array and take the last value as Max.

http://www.anthony-vba.kefra.com/vba/excelvba-simulation.htm#Sorting_Numbers_In_an_Array