Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a vba message box that uses html

Tags:

vba

How can I return a message box with functioning HTML tags using VBA? example

    dim mtext as string
    mtext = "<em>hello</em> <br> world"
    msgbox mtext
like image 455
Daniel L. VanDenBosch Avatar asked Apr 04 '17 18:04

Daniel L. VanDenBosch


1 Answers

You don't. The MsgBox function is just a thin wrapper over a Win32 API function, and that function doesn't deal with HTML input. HTML is for web browsers, not desktop applications.

The closest thing you could get is a custom UserForm with a RichTextBox control, but that's OCX tech developped for Visual Basic 6.0 and probably won't work on x64 machines, not to mention that it will definitely break down if you need to distribute your macro to users that don't have the OCX on their machines.


A better alternative could be to make a COM-visible class library in your favorite .NET language (C#, VB.NET), and expose a custom MessageBox function that displays a WinForms dialog featuring a System.Windows.Forms.RichTextBox control that can process and display RTF formatted text.

You then need to distribute and register your COM type library to your users.

In other words, it can be done - it only depends how badly you want it.

like image 97
Mathieu Guindon Avatar answered Oct 13 '22 15:10

Mathieu Guindon