Calling a DLL based Macro from worksheet

hcdusty

New Member
Joined
Jul 21, 2014
Messages
2
Hi All,
We have successfully implemented a VBA macro ( below ) that calls and executes a function from a DLL. We are happy with the macro as
it behaves as expected. Now, however, we'd like to call the Function that the macro runs from a worksheet cell. The function name (PEEP) appears
in the formula autocomplete, but once we pass in the arguments, all we get is a #Name?. Would appreciate your thoughts and help.

Here's the call of the function from the worksheet:
=PEEP(F3,B2:B2001,E11,F4,I3,J3,F5,J19,J18,2000,1)

Here's the VBA Macro Code:

Option Explicit
Option Base 1
Public Declare Function PEEP Lib _
"C:\Excel Unit Test Builder\Measurement Functions.dll" _
(ByVal referenceTriggerIndex As Double, ByRef y As Double, ByVal dt As Double, _
ByVal t0 As Double, ByVal expectedLowLimit As Double, ByVal expectedHighLimit As Double, _
cursorIndices As Double, passFail As Integer, result As Double, ByVal yArraySize As Long, ByVal ciAarraySize As Long) As Long

Sub Endpressure()
'=================================================================================
' Declare varibles here
'=================================================================================
Dim pres_array_size As Integer ' Constant: Holds pressure array size from the worksheet
Dim testvariable As Double ' Placeholder variable for Input or Output values
Dim passFail As Integer ' Output: Holds Pass/Fail Result
Dim result As Double ' Output: Holds measured PEEP Value
Dim y() As Double ' Input: Array that holds all baseline pressure values
Dim expectedLowLimit As Double ' Input: Holds PEEP high limit
Dim expectedHighLimit As Double ' Input: Holds PEEP low limit
Dim referenceTriggerIndex As Double ' Input: Holds start point for PEEP measurement
Dim dt As Double ' Input: Holds sample rate of pressure data
Dim t0 As Double ' Input: Holds value where pressure waveform begins
Dim cursorIndices(2) As Double ' Output: Holds cursor placement data
Dim yArraySize As Long ' DLL Field: Holds Array Size info
Dim ciAarraySize As Long ' DLL Field: Holds Cursor Array info
Dim Pass_Fail As String ' Used to convert passFail integer into "Pass" or "Fail" string
Dim iterate As Integer

'=================================================================================
' Load the variables from the worksheet here
'=================================================================================

pres_array_size = Worksheets("waveform data").Cells(11, 7).Value
expectedLowLimit = Worksheets("waveform data").Cells(3, 9).Value
expectedHighLimit = Worksheets("waveform data").Cells(3, 10).Value
referenceTriggerIndex = Worksheets("waveform data").Cells(3, 6).Value
dt = Worksheets("waveform data").Cells(11, 5).Value
t0 = Worksheets("waveform data").Cells(3, 6).Value
yArraySize = Worksheets("waveform data").Cells(11, 7).Value
ciAarraySize = 2
ReDim y(pres_array_size)

'=================================================================================
' Load the y baseline pressure array from the worksheet here
'=================================================================================

For iterate = 2 To (pres_array_size - 1)

y(iterate) = Worksheets("waveform data").Cells(iterate, 2).Value

Next

'=================================================================================
' Call and process the DLL here
'=================================================================================
Call PEEP(referenceTriggerIndex, y(1), dt, t0, expectedLowLimit, expectedHighLimit, cursorIndices(1), passFail, result, yArraySize, ciAarraySize)
If passFail = 0 Then Pass_Fail = "Fail"
If passFail = 1 Then Pass_Fail = "Pass"

'=================================================================================
' Display the results on the spreadsheet here
'=================================================================================
Worksheets("waveform data").Cells(10, 18).Value = result
Worksheets("waveform data").Cells(11, 18).Value = Pass_Fail



End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top