Create a vba message box that uses html - 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

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.

I would custom design a form and then have the text set based on your needs specifically. May I ask why you are wanting to use HTML codes? Cause, it may be simple enough to create your own library/class to handle the processing, before pushing to a rich text box. However, the Rich Text Box is only going to be in VB, like using VB Studio Express. With VBA, you're sort of stuck...sorry.

Related

Embedding Word Object into VB.Net Winform

I wondering if its possible to use Microsoft Word as a text editor in a VB.Net project?
My project currently uses a Rich Text Box to allow the user to right a report which is then saved and a report generated. I was wondering if i could switch to Word for better formatting and layout options, be it embedded in the actual form or in another form thats called (if that makes it easier to assign the control).
I have worked on opening Word itself via a button click but would like to have it incorporated in the project. All users that would actually use the program would have one of the more recent versions of word installed.
Any pointers to websites would be great as i'm constantly searching but not getting very far
Thanks

Outlook Addin doesn't render HTML forms using VSTO but using C++ API does

I am rewriting C++ Outlook Addin application to it full .NET representation using VSTO (Outlook 2007/2010).
One of the features to rewrite is html forms rendering. User can select checkbox, provide input, select option etc. in compose mail mode (before sending). But when I put any input markup to HTMLBody property it isn't rendered as expected. Instead only something like http://postimage.org/image/jk9swfr2t/ is rendered. I spent a very long time to search for a solution but it always ultimately turned out to be impossible due to Word based Outlook HTML render engine.
Our C++ addin code repository is extremely large and is legacy - I am not a c++ developer and don't know to much about COM and c++ outlook corresponding APIs, the target is to rewrite according to existing functionalities, there is simply no time and no resources to analize legacy code.
But the most interesting to me is that c++ version of software render everything: inputs, checkbox, select option, just everything! So I guessed it is possible and started looking for a workaround or any kind of hack.
I analyzed the old c++ addin using OutlookSpy tool and it turned out that it doesn't fill HTMLBody. I had to wade through a partial legacy code and found that it set PR_HTML MAPI property. Unfortunately I found also that this property is not available in vsto so I can't check if it helps.
So my questions are:
do you know any hacks to render HTML forms in Outlook using VSTO?
are there any differences using item.HTMLBody or PR_HTML MAPI property which can have impact on my problem?
if yes then can I set PR_HTML using C#? (I've checked free http://www.add-in-express.com/creating-addins-blog/2008/11/21/outlook-object-model-propertyaccessor-storageitem/ but it doesn't work for me - code doesn't execute when I add AddExpress.MAPI.dll)
Everything must be done programmatically so inserting using Outlook UI or exporting to Outlook from IE doesn't count. Also we can't use commercial third party tools like Redemption or Add-in Express.
Are you sure you posted the right picture? :-)
Keep in mind that Outlook uses Word to render HTML, so any input controls and scripts will not run.

VB.NET MessageBox with markup in forms

I want to show a MessageBox in a VB.NET application that has special markup for its text. More specifically, I want to display an unordered list. I tried doing it by wrapping the text in HTML tags (which Java Swing supports for example, if I'm not mistaken) and working with <ul> and <li>. This did not work. I can't find anything on the net about it either...
The textbox is used in a normal Windows forms application.
Does anyone know how to do it without creating a completely custom messagebox class?
As Hans Passant says, this is not possible with the default MessageBox in VB.NET.

How to get selected text from a webpage?

I need to retrieve only selected portion of a webpage (user open a webpage in web-browser control, then he/she would select some portion of a webpage, i just need only those selected portion/text) in vb.net in visual basic language. How to do ?
i am using microsoft visual studio 2008
Language: Visual Basic
FrameWork: vb.net 3.5
Perhaps here are some answers for you(first post attachment):
Manipulate/Change/Form Fill data in webpages using the Webbrowser control
In terms of IE's API, you can get the select text by getting the selection object via IHTMLDocument2::Selection the property, then create a range object via IHTMLSelectionObject::createRange. If the return range's type property is "Text", you can then query IHTMLTxtRange from it and get the selected text via IHTMLTxtRange::text.
It is unclear which webbrowser control you are referring to. There are 3 webbrowser controls in the .Net Framework, one in Windows Forms, one in WPF, and one in Silverlight. Anyway, you can call InvokeScript or use the unmanaged interface like csexwb's GetSelectedText, if one of the method is supported by your control library.
Next time mention which control library you are using when you ask the question. Merely mentioning the language you choose isn't enough to resolve the ambiguity in class names.

Sharepoint form layout in VB

OKay, I'm from a PHP background, but I've just been tasked with developing some custom Web Parts in SharePoint. I've figured out how to create and deploy a basic "Hello world" web part in VB. Okay so far.
What I'm stuck on is a really basic, stupid point - how the hell do I lay out things in a VB web part?
For an example, here's a label and a textbox:
protected overrides sub createchildcontrols()
mybase.createchildcontrols
dim mylabel as new label
dim mytextbox as new textbox
mylabel.text ="My label text"
mytextbox.text ="My textbox"
me.controls.add(mylabel)
me.controls.add(mytextbox)
How would I, for example, get mylabel and my textbox to appear on different lines, rather than running one after the other as they do now? In PHP I'd just wrap them in some top break them onto differnt lines, but how do I do it here?
There are a number of ways to go about it. The easiest, if you really just want the controls to appear on different lines would be to add an ASP.net LiteralControl with a BR tag between them.
Aside from that, you can always use the ASP.net formatting controls, like Table to break your controls into sections for output.
Additionaly, everything that derives from WebControl has an Attribues and CssClass property for setting formatting based on style-sheets you can use.
The last method, and the most customizable, but hardest to maintain and change, would be to override the webpart's Render method and generate your HTML completely by hand in the WebPart.
Alternately, you could scrap this altogether, and employ the SmartPart to develop ASP.net user controls for use inside of SharePoint, giving you the options to use the Visual Studio designer tools to layout your controls on the form.
You should override the Render() method. By default this method just renders all the child controls you have added in the CreateChildControls() method, but overriding it lets you write additional HTML elements around the controls.
I usually code in C#, but I think the following example should work in VB:
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.Write("<h1>Custom webpart rendering</h1>")
me.mylabel.RenderControl(writer)
writer.Write("<br />")
me.myTextbox.RenderControl(writer)
End Sub
Give it a try...
I've been developing web parts for an ASP.NET site using the standard web user control model, which gives you access to the VS designer and means your UI can be standard HTML. ASP.NET then wraps the UserControl into a GenericWebPart at runtime to host it in a WebParts site.
I know that Sharepoint doesn't support this model out of the box but I've just found this which might help you...
http://weblogs.asp.net/jan/archive/2006/12/02/announcing-the-return-of-the-smartpart.aspx
Smart Part (or a variation of it) is the easiest way to go. Why mess with rendering direct html when you can develop a user control more easily?
Plus if you are not an expert in VB, having Visual Studio Designer will help with creating user controls
i blogged about this very topic. Easily build a rich UI for a web part without using SmartPart
Thanks for all the responses. I've gone with EvilGoatBobs solution as the most immediately easy to implement.
This is my first time on StackOverflow and your helpful answers have made it a really good introduction to the site! :)