In this example we create a new formula that passes 2 parameters "Hello" and "World" from Excel to VBA to PB, the PB code Capitilises the first parameter, displays both parameters individually, then returns a single (modified) string back to VBA which in turn passes the "HELLO world value back to Excel.
PB2VB2XLdll can be called as an Excel function directly, but produces unexpected and undesirable results (sometimes crashy)
The trick to getting it working seems to be by calling PB2VB2XLdll via the proxy function PB2VB2XLvba
Anyway, I hope this proves useful to others & thanks to srod for help in working this out. If anyone knows why the DLL cant be called directly from Excel (and instead needs to be called via a intermediary VBA function) I'd be interested...
Excel Formula:
Code: Select all
=PB2VB2XLvba("Hello","World")
Excel VBA in Module1
Code: Select all
Public Declare Function PB2VB2XLdll Lib "C:\PB2VB2XL.dll" (ByVal PARAM1 As String, ByVal PARAM2 As String) As String
Public Function PB2VB2XLvba(PARAM1 As String, PARAM2 As String) As String
PB2VB2XLvba = PB2VB2XLdll(PARAM1, PARAM2)
End Function
PB Code Compiled as a DLL with UTF-8 coding
Code: Select all
ProcedureDLL.l PB2VB2XLdll(PARAM1$, PARAM2$)
PARAM1$ = UCase(PARAM1$)
MessageRequester("PB INFO", PARAM1$)
MessageRequester("PB INFO", PARAM2$)
ProcedureReturn SysAllocString_(PARAM1$ + " " + PARAM2$)
EndProcedure