Having problem with 2000 to 97 conversion

jfgambit

New Member
Joined
Apr 2, 2003
Messages
14
I have built a nice employee time tracking device in Excel 2000. It is pretty self explanitory ("IN" time, "OUT" time, total time, etc). What I am having problems with is the VB code that is behind the "OUT" time. In essence, once an "OUT" time is entered, the ms error message box is overwritten to ask what type of break the person took (No Lunch, 1/2 hour, 1 hour) and takes the response and implements it into the Total hours calculation. Works great in 2000, but the users are getting problems in 97. i don't have 97 and can't seem to trouble shoot it. Could some guru with 97 have a look at this and see what exactly I am missing in 97.

The code is a manipulation of Ken Getz's brilliance by Stratos. Which can be viewed at the following: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=39D37A29.99BF2A63@csv.warwick.ac.uk

If anyone can help, please let me know and I can send you a copy of the Excel sheet. Really appreciate the help.

THANKS.


Thanks for any help
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Ivan:

I orginally wrote:

If anyone can help, please let me know and I can send you a copy of the Excel sheet. Really appreciate the help.

Unfortunately, the file is 678K zipped and I cannot attach it to the board due to size limitations. I can send you a copy if you give me an e-mail address. PM me if you do not want it publically displayed.

Thanks
 
Upvote 0
Hello,

jfgambit said:
I have built a nice employee time tracking device in Excel 2000. It is pretty self explanitory ("IN" time, "OUT" time, total time, etc).

Alright, here's the origination of this quandary, just so that readers know what the issue is, it's addressof, and I don't have the correct .dll to test/work with Mr. Getz's workaround.

I still stick with my follow-up advice:

I didn't steer you down this road with '97 in mind originally, had I known that's what you're using, I might have recommended something else... (Userform)

I think you should create and use a userform. This gets messy, even if you have '97 you still may or may not have the correct .dll file, you almost need to run a file search, which is not going to be efficient...

I'm quite certain Ivan can help, he is a guru, perhaps he has the correct .dll. If you don't want to mess with it Ivan, I'll take the file @

Nate@TheOfficeExpertsNoSpam.com (remove NoSpam) and impliment a userform approach.

Although, I would like to see a functioning variety of this with respect to Excel '97 as I can't test it, without downloading the file (which I should possibly purse...).
 
Upvote 0
NateO said:
Hello,

jfgambit said:
I have built a nice employee time tracking device in Excel 2000. It is pretty self explanitory ("IN" time, "OUT" time, total time, etc).
laugh.gif


Alright, here's the origination of this mess/quandary, just so that readers know what the issue is, it's addressof, and I don't have the correct .dll to test/work with Mr. Getz's workaround.

I still stick with my follow-up advice:

I didn't steer you down this road with '97 in mind originally, had I known that's what you're using, I might have recommended something else... (Userform)

I think you should create and use a userform. This gets messy, even if you have '97 you may have differing .dll files, you almost need to run a file search, which is not going to be efficient...

I'm quite certain Ivan can help, he is a guru, perhaps he has the correct .dll. If you don't want to mess with it Ivan, I'll take the file @

Nate@TheOfficeExpertsNoSpam.com (remove NoSpam).

Although, I would like to see a functioning variety of this with respect to Excel '97 as I can't test it, without downloading the file (which I should possibly purse...).

Hi NateO
How are you :)
If he emails me I can have a look...but from a quick look I think
all he needs to do is Find the DLL and explicitly set the Function path to this
eg

Private Declare Function GetCurrentVbaProject Lib "C:\etc\etc\vba332.dll" _
 
Upvote 0
Hello Ivan,

Ivan F Moala said:
Hi NateO
How are you :)
If he emails me I can have a look...but from a quick look I think
all he needs to do is Find the DLL and explicitly set the Function path to this
eg

Private Declare Function GetCurrentVbaProject Lib "C:\etc\etc\vba332.dll" _

Doing well, thanks! You?

That was my thought in the linked post, I just can't test it.... Api by eyesight, interesting...

While api calls are efficient, the quandary involves a worksheet change event, and, apparently used by both xl '97 and '00 users, so it'll need both the customized workaround and the vb =>6 addressof function. I'm certain it's possible, but is it worth it....?

Still, interested though. Hope all is well with you. :)
 
Upvote 0
Nate and Ivan:

Sorry I have not replied, and it's nice to see that someone was still looking at this. i have been building an HR tracking database and dealing with some a new SAP/Oracle data warehousing problem and just recently heard from the individual having problems.

First off, Nate in no way did I not appreciate your help, but since you quoted that you could not help since you did not have 97 then i turned to an alternate source.

With that said the individual using the Excel sheet sent me the Debugging that occured when openning the sheet. The following line was highlighted for debugging:

Dim mbFlags As VbMsgBoxStyle

Ivan. I will send you a copy of the excel sheet. I have checked the references and ran the following as suggest by Nate:

Sub test()
Dim test As VbMsgBoxStyle, Z As Long
MsgBox VarType(test)
MsgBox VarType(Z)
End Sub

Problem is I have 2000 and the individual using this is not that advanced to help with the debugging. Sending something back and forth and asking him to check things only confuses him.

So any help would be greatly appreciated.

Nate and Ivan...again thanks for the time and effort into looking into this.
 
Upvote 0
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
 
Upvote 0
Ivan:

Thanks! I look forward to reviewing the spreadsheet and your updates.

Thank you both for your time in regards to this matter.

Jeff
:LOL:
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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