Consulting

Results 1 to 9 of 9

Thread: Solved: Self Closing Message Box

  1. #1

    Solved: Self Closing Message Box

    HI.
    In Win XP, OFFICE-2003 I have issue while trying to get to work.
    http://cuinl.tripod.com/Tips/messagboxclsing.htm

    [VBA]
    Public Const NV_CLOSEMSGBOX As Long = &H5000&
    Public Declare Function SetTimer& Lib "user32" (ByVal hWnd&, ByVal nIDEvent&, _
    ByVal uElapse&, ByVal lpTimerFunc&)
    Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName$, ByVal lpWindowName$)
    Public Declare Function LockWindowUpdate& Lib "user32" (ByVal hwndLock&)
    Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hWnd&)
    Public Declare Function MessageBox& Lib "user32" Alias "MessageBoxA" _
    (ByVal hWnd&, ByVal lpText$, ByVal lpCaption$, ByVal wType&)
    Public Declare Function KillTimer& Lib "user32" (ByVal hWnd&, ByVal nIDEvent&)
    Public Const API_FALSE As Long = 0&
    Public Sub TimerProc(ByVal hWnd&, ByVal uMsg&, ByVal idEvent&, ByVal dwTime&)
    KillTimer hWnd, idEvent
    Dim hMessageBox&
    'Replace 'Self Closing Message Box' with the title you gave to your message box.
    hMessageBox = FindWindow("#32770", "Self Closing Message Box")
    If hMessageBox Then
    Call SetForegroundWindow(hMessageBox)
    SendKeys "{enter}"
    End If
    Call LockWindowUpdate(API_FALSE)
    End Sub

    'Insert this code to your form:
    Private Sub Form_Load()
    'Replace the '4000' below with the number of milliseconds the message box
    'will appear. 1000 milliseconds = 1 second

    SetTimer hWnd, NV_CLOSEMSGBOX, 4000&, AddressOf TimerProc
    Call MessageBox(hWnd, "Watch this message box close itself after four seconds", _
    "Self Closing Message Box", MB_ICONQUESTION Or MB_TASKMODAL)
    End Sub
    [/VBA]

  2. #2
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    is there some reason that this has to be a msgbox?

    It's so easy with a userform.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    My project works like this:
    1.When process start Excel application set=0 (Hide).
    User interference = 0
    2.Userform shows vb modeless.
    3.Before download (IE) process user select different items in opened Webpage dropdown.
    2.MsgBox (or Windows Taskbar Button - new excel icon???) should say process status or tell for user what to do.

    Sry my still bad english.

  4. #4
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Why does it have to be a msgbox?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Of course not necessariliy MsgBox.
    I was truing to use FlashWindow for send message to Application Caption in Taskbar, but not successfully.
    http://support.microsoft.com/kb/254339

    If Wbk hidden then how send message in taskbar like in attachment?
    Or should I make temporarly new file and use it Taskbar Caption?
    Last edited by omnibuster; 03-19-2010 at 02:50 PM.

  6. #6

  7. #7
    Thanks all.
    I was think that way:

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Very neat. A couple of minor comments.

    Hide seems unneeded if the form is unloaded
    [VBA]
    Unload UF2
    UF2.Hide
    [/VBA]
    You could Toggle Excel visible if desirable
    [VBA]
    Private Sub CommandButton2_Click()
    Application.Visible = Not Application.Visible
    End Sub

    [/VBA]
    Initialise rather than Activate - no need to repaint
    [VBA]Public Sub UserForm_initialize()
    With UF2
    'etc.
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Thanks mdmackillop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •