OK, I got it to work....you were missing
1) The Actuall Function call
2) Addressof function wasn't called properly
3) I had use use Interger consts in place of std VbMsgboxstyles ??
'NOTE: The brilliant AddrOf function herein contained is the work of Ken Getz and
'Michael Kaplan. Published in the May 1998 issue of
'Microsoft Office & Visual Basic for Applications Developer (page 46).
'Office 97 does not support the "AddressOf" operator which is needed to tell Windows
'where our "call back" function is. Getz and Kaplan figured out a workaround.
Any way here is what I got to Work
<font face=Courier New><SPAN style="color:darkblue">Option</SPAN> <SPAN style="color:darkblue">Explicit</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_YESNOCANCEL = &H3&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_YESNO = &H4&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_RETRYCANCEL = &H5&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_OKCANCEL = &H1&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_OK = &H0&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_ABORTRETRYIGNORE = &H2&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_ICONEXCLAMATION = &H30&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_ICONQUESTION = &H20&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_ICONASTERISK = &H40&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> MB_ICONINFORMATION = MB_ICONASTERISK
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> IDOK = 1
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> IDCANCEL = 2
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> IDABORT = 3
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> IDRETRY = 4
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> IDIGNORE = 5
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> IDYES = 6
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> IDNO = 7
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> IDPROMPT = &HFFFF&
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> WH_CBT = 5
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> GWL_HINSTANCE = (-6)
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Const</SPAN> HCBT_ACTIVATE = 5
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Type</SPAN> MSGBOX_HOOK_PARAMS
hwndOwner <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
hHook <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Type</SPAN>
<SPAN style="color:darkblue">Private</SPAN> MSGHOOK <SPAN style="color:darkblue">As</SPAN> MSGBOX_HOOK_PARAMS
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetCurrentThreadId _
<SPAN style="color:darkblue">Lib</SPAN> "kernel32" () _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetDesktopWindow Lib _
"user32" () _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetWindowLong _
<SPAN style="color:darkblue">Lib</SPAN> "user32" _
Alias "GetWindowLongA" ( _
<SPAN style="color:darkblue">ByVal</SPAN> hwnd <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> nIndex <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> MessageBox _
<SPAN style="color:darkblue">Lib</SPAN> "user32" _
Alias "MessageBoxA" ( _
<SPAN style="color:darkblue">ByVal</SPAN> hwnd <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> lpText <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> lpCaption <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> wType <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> SetDlgItemText _
<SPAN style="color:darkblue">Lib</SPAN> "user32" _
Alias "SetDlgItemTextA" ( _
<SPAN style="color:darkblue">ByVal</SPAN> hDlg <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> nIDDlgItem <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> lpString <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> SetWindowsHookEx _
<SPAN style="color:darkblue">Lib</SPAN> "user32" _
Alias "SetWindowsHookExA" ( _
<SPAN style="color:darkblue">ByVal</SPAN> idHook <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> lpfn <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> hmod <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> dwThreadId <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> SetWindowText _
<SPAN style="color:darkblue">Lib</SPAN> "user32" _
Alias "SetWindowTextA" ( _
<SPAN style="color:darkblue">ByVal</SPAN> hwnd <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> lpString <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> UnhookWindowsHookEx _
<SPAN style="color:darkblue">Lib</SPAN> "user32" ( _
<SPAN style="color:darkblue">ByVal</SPAN> hHook <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> mbFlags <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN> <SPAN style="color:green"><SPAN style="color:green">'VbMsgBoxS</SPAN></SPAN>
<SPAN style="color:darkblue">Dim</SPAN> mbFlags2 <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN> <SPAN style="color:green"><SPAN style="color:green">'VbMsgBoxS</SPAN></SPAN>
<SPAN style="color:darkblue">Dim</SPAN> mTitle <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> mPrompt <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> But1 <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> But2 <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> But3 <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Public</SPAN> y <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Double</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Function</SPAN> MessageBoxH(hwndThreadOwner <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
hwndOwner <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, mbFlags <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:green">'This function calls the hook</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> hInstance <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> hThreadId <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
hInstance = GetWindowLong(hwndThreadOwner, GWL_HINSTANCE)
hThreadId = GetCurrentThreadId()
<SPAN style="color:darkblue">With</SPAN> MSGHOOK
.hwndOwner = hwndOwner
.hHook = SetWindowsHookEx(WH_CBT, AddrOf("MsgBoxHookProc"), hInstance, hThreadId)
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
MessageBoxH = MessageBox(hwndOwner, Space$(120), Space$(120), mbFlags)
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> MsgBoxHookProc(<SPAN style="color:darkblue">ByVal</SPAN> uMsg <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> wParam <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, <SPAN style="color:darkblue">ByVal</SPAN> lParam <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:green">'This function catches the messagebox before it opens</SPAN>
<SPAN style="color:green">'and changes the text of the buttons - then removes the hook</SPAN>
<SPAN style="color:darkblue">If</SPAN> uMsg = HCBT_ACTIVATE <SPAN style="color:darkblue">Then</SPAN>
SetWindowText wParam, mTitle
SetDlgItemText wParam, IDPROMPT, mPrompt
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> mbFlags
<SPAN style="color:darkblue">Case</SPAN> vbAbortRetryIgnore
SetDlgItemText wParam, IDABORT, But1
SetDlgItemText wParam, IDRETRY, But2
SetDlgItemText wParam, IDIGNORE, But3
<SPAN style="color:darkblue">Case</SPAN> vbYesNoCancel
SetDlgItemText wParam, IDYES, But1
SetDlgItemText wParam, IDNO, But2
SetDlgItemText wParam, IDCANCEL, But3
<SPAN style="color:darkblue">Case</SPAN> vbOKOnly
SetDlgItemText wParam, IDOK, But1
<SPAN style="color:darkblue">Case</SPAN> vbRetryCancel
SetDlgItemText wParam, IDRETRY, But1
SetDlgItemText wParam, IDCANCEL, But2
<SPAN style="color:darkblue">Case</SPAN> vbYesNo
SetDlgItemText wParam, IDYES, But1
SetDlgItemText wParam, IDNO, But2
<SPAN style="color:darkblue">Case</SPAN> vbOKCancel
SetDlgItemText wParam, IDOK, But1
SetDlgItemText wParam, IDCANCEL, But2
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
UnhookWindowsHookEx MSGHOOK.hHook
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
MsgBoxHookProc = <SPAN style="color:darkblue">False</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Function</SPAN> BBmsgbox(mhwnd <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
mMsgbox <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>, _
Title <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, _
Prompt <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, _
<SPAN style="color:darkblue">Optional</SPAN> mMsgIcon <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>, _
<SPAN style="color:darkblue">Optional</SPAN> ButA <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, _
<SPAN style="color:darkblue">Optional</SPAN> ButB <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, _
<SPAN style="color:darkblue">Optional</SPAN> ButC <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>) _
As <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:green">'This function sets your custom parameters and returns</SPAN>
<SPAN style="color:green">'which button was pressed as a string</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> mReturn <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
mbFlags = mMsgbox
mbFlags2 = mMsgIcon
mTitle = Title
mPrompt = Prompt
But1 = ButA
But2 = ButB
But3 = ButC
mReturn = MessageBoxH(mhwnd, GetDesktopWindow(), mbFlags <SPAN style="color:darkblue">Or</SPAN> mbFlags2)
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> mReturn
<SPAN style="color:darkblue">Case</SPAN> IDABORT
BBmsgbox = But1
<SPAN style="color:darkblue">Case</SPAN> IDRETRY
BBmsgbox = But2
<SPAN style="color:darkblue">Case</SPAN> IDIGNORE
BBmsgbox = But3
<SPAN style="color:darkblue">Case</SPAN> IDYES
BBmsgbox = But1
<SPAN style="color:darkblue">Case</SPAN> IDNO
BBmsgbox = But2
<SPAN style="color:darkblue">Case</SPAN> IDCANCEL
BBmsgbox = But3
<SPAN style="color:darkblue">Case</SPAN> IDOK
BBmsgbox = But1
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Sub</SPAN> PrmptUserTest()
<SPAN style="color:darkblue">Dim</SPAN> mReturn <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
mReturn = BBmsgbox(1, vbYesNoCancel, _
"Enter Your Break", "Please enter a lunch break: " & _
" 0 = No, 1 = 1/2 hour, 2 = 1 hour", vbInformation, "0", "1", "2")
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> mReturn
<SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "0"
y = 0
<SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "1"
y = 0.5
<SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "2"
y = 1
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
MsgBox "mReturn:= " & mReturn & vbCr & " Lunch break:=" & y & " hr TOO LONG!"
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN>
<SPAN style="color:darkblue">Private</SPAN> <SPAN style="color:darkblue">Function</SPAN> AddrOf(CallbackFunctionName <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> aResult <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, CurrentVBProject <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, strFunctionId <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> AddressofFunction <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, UniCbkFunctionName <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
UniCbkFunctionName = StrConv(CallbackFunctionName, vbUnicode)
<SPAN style="color:darkblue">If</SPAN> <SPAN style="color:darkblue">Not</SPAN> GetCurrentVbaProject(CurrentVBProject) = 0 <SPAN style="color:darkblue">Then</SPAN>
aResult = GetFuncID(hProject:=CurrentVBProject, _
strFunctionName:=UniCbkFunctionName, _
strFunctionId:=strFunctionId)
<SPAN style="color:darkblue">If</SPAN> aResult = 0 <SPAN style="color:darkblue">Then</SPAN>
aResult = GetAddr(CurrentVBProject, _
strFunctionId, lpfn:=AddressofFunction)
<SPAN style="color:darkblue">If</SPAN> aResult = 0 <SPAN style="color:darkblue">Then</SPAN>
AddrOf = AddressofFunction
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
</FONT>
The Actual Function calls that were missing
<font face=Courier New><SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetCurrentVbaProject _
<SPAN style="color:darkblue">Lib</SPAN> "vba332.dll" _
Alias "EbGetExecutingProj" ( _
hProject <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetFuncID _
<SPAN style="color:darkblue">Lib</SPAN> "vba332.dll" _
Alias "TipGetFunctionId" ( _
<SPAN style="color:darkblue">ByVal</SPAN> hProject <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> strFunctionName <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, _
<SPAN style="color:darkblue">ByRef</SPAN> strFunctionId <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Declare</SPAN> <SPAN style="color:darkblue">Function</SPAN> GetAddr _
<SPAN style="color:darkblue">Lib</SPAN> "vba332.dll" _
Alias "TipGetLpfnOfFunctionId" ( _
<SPAN style="color:darkblue">ByVal</SPAN> hProject <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, _
<SPAN style="color:darkblue">ByVal</SPAN> strFunctionId <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, _
<SPAN style="color:darkblue">ByRef</SPAN> lpfn <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) _
As <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN>-------------------------------------------------------------------------------------------------------------------</SPAN></SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> AddrOf</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> Returns a function pointer of a VBA public function given its name. This function</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> gives similar functionality to VBA as VB5 has with the AddressOf param type.</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> NOTE: This function only seems to work if the proc you are trying to get a pointer</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> to is in the current project. This makes sense, since we are using a function</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> named EbGetExecutingProj.</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN>-------------------------------------------------------------------------------------------------------------------</SPAN></SPAN>
<SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> AddrOf(strFuncName <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> hProject <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> lngResult <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> strID <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> lpfn <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> strFuncNameUnicode <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Const</SPAN> NO_ERROR = 0
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> The function name must be in Unicode, so convert it.</SPAN>
strFuncNameUnicode = StrConv(strFuncName, vbUnicode)
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> Get the current VBA project</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> The results of GetCurrentVBAProject seemed inconsistent, in our tests,</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> so now we just check the project handle when the function returns.</SPAN>
<SPAN style="color:darkblue">Call</SPAN> GetCurrentVbaProject(hProject)
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> Make sure we got a project handle... we always should, but you never know!</SPAN>
<SPAN style="color:darkblue">If</SPAN> hProject <> 0 <SPAN style="color:darkblue">Then</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> Get the VBA function ID (whatever that is!)</SPAN>
lngResult = GetFuncID( _
hProject, strFuncNameUnicode, strID)
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> We have to check this because we GPF if we try to get a function pointer</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> of a non-existent function.</SPAN>
<SPAN style="color:darkblue">If</SPAN> lngResult = NO_ERROR <SPAN style="color:darkblue">Then</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'</SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN> Get the function pointer.</SPAN>
lngResult = GetAddr(hProject, strID, lpfn)
<SPAN style="color:darkblue">If</SPAN> lngResult = NO_ERROR <SPAN style="color:darkblue">Then</SPAN>
AddrOf = lpfn
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
</FONT>
I'll send the workbook