The PODA Blog

News, views and articles from our membership

Archive for January 22nd, 2008

Putting the Microsoft WebBrowser to Work

Posted by Derek Mang on 22nd January 2008

The Microsoft Webbrowser control (windows\system32\shdocvw.dll) may be included in the VBA controls toolbox and subsequently used to present web pages within a userform or other MS Office container.

I typically develop application “help” files using MS Frontpage and until recently have been using the FollowHyperlink method (Excel, Word) to present the help page using Internet Explorer.  When this method is used, IE is fired up and presents information as expected with the machine-typical delay for application startup.

A recent development has changed my thinking some.  Briefly stated, this VBA application is built within MS Outlook, and logs information against a background Excel spreadsheet.  It’s built within Outlook because there’s a fair bit of email communication with other parties.  One of the other parties provides status data via the internet, and also provides a reference number within their communication which is logged (a business rule).

Like many VBA applications,  this one replaces a lot of manual effort, and one of the manual tasks was to navigate to the website mentioned above to check on the item status.

To simplify this task, I used a userform with a listbox and a Webbrowser control.  When the form is displayed, a list of reference numbers is provided.  Click on a listed item, and the Webbrowser “navigate2″ method is fired up with the URL (a constant previously captured) and reference number appended appropriately.  The corresponding page is presented, and it’s a lot faster than instantiating IE!!. Click another list item and a new page is presented - all the while working within Outlook!

I am in the process of updating other applications to present their Help in a userform based webbrowser, for the same reasons (faster, less system overhead, cleaner desktop).

Another usage of the Webrowser control is also nearing completion. This one is a VBA Code view / print function with a twist - the twist being the ability to choose your own colour / font combination for keywords and phrases, as well as being able to add your own keywords and phases.

I have taken the time to capture VBA keywords (ie. Integer, Dim, Instr) along with HTML supported colours and font names into a simple MS Access database.  To this, I’ve added a userform where you can manage the HTML attributes of the keyword or phrase (i.e. anything with a space is considered a phase - End If, End With for example).

The main userform provides dropdowns for the VBA project, object within the project (module, userform), and component within the object (sub, function), as well as the Webbrowser window for viewing the code.

Within the webbrowser window you can select text by dragging the mouse, or right-click to present a menu which includes the Print function among others. 

It’s pretty much wrapped up. It’s also available to our PODA membership! If interested, please contact me and I’ll send you a copy.

Posted in Office (All) | 9 Comments »