none
VBA MsgBox hides under C# Form (TopMost=true) RRS feed

  • Question

  • Hello,

    I have problem with Excel VBA MsgBox which hides under my C# Visual Studio Form. Form has TopMost=true, and this can't be different.

    From Ribbon I'm calling my Form, there are few buttons which use VBA code for example:

    Globals.ThisAddIn.Application.Run("Server.xlsm!GatherIntel");

    In VBA there is error handler to show error if anything wrong comes up, but problem comes that VBA MsgBox hides under my c# Form user can't click anything else on Excel or Form. The only buttons can save user from "End Task" is -> "Enter, space or Esc" buttons, that can "silent" press "OK" button.

    How can i make VBA MsgBox to be most top?

    Wednesday, February 19, 2020 9:11 AM

All replies

  • Hi Vytautas A,

    In advance, sorry, if I misunderstand your question.
    I'd like to confirm:
    The Excel with VBA is called from C# application, or launched manually (instead by C# code)?

    Regards,

    Ashidacchi -- http://hokusosha.com

    Wednesday, February 19, 2020 9:53 AM
  • Form is called from Excel Ribbon menu which is part of VSTO and managed by c# code. Form is created with VS2010 and Button is calling VBA code via this line: 
    Globals.ThisAddIn.Application.Run("Server.xlsm!GatherIntel");
    Wednesday, February 19, 2020 9:59 AM
  • If so, how about make Excel top-most in C# code?

    Ashidacchi -- http://hokusosha.com

    Wednesday, February 19, 2020 10:57 AM
  • If so, how about make Excel top-most in C# code?

    Ashidacchi -- http://hokusosha.com

    I would gladly make Excel "MsgBox" on top of everything, but how?
    Wednesday, February 19, 2020 11:21 AM
  • Here's another thought.

    Instead of using the VBA MsgBox function use VBA to call the Win32 MessageBox function.  The Win32 function allows to set the MB_TOPMOST flag.  Perhaps this will allow the message box to display on top of the C# form.

    Wednesday, February 19, 2020 11:35 AM
  • Here's another thought.

    Instead of using the VBA MsgBox function use VBA to call the Win32 MessageBox function.  The Win32 function allows to set the MB_TOPMOST flag.  Perhaps this will allow the message box to display on top of the C# form.

    Hmz, not bad idea actually. I will give a try and will update this thread.
    Wednesday, February 19, 2020 11:42 AM