If you have a embedded browser in your Windows application, you may be encountering a rendering or some other kind of compatibility issue with the content you are trying to display. In this post, I’ll talk about some options to try to fix those issues. The web browser control is known by many names: WebBrowser control, WebOC, shdocvw, ieframe, etc. I prefer calling it the Web Browser control but what ever you like to call it, the compatibility issues and solutions are the same.
What are the Defaults?
I was at a restaurant once with some friends. When the waitress asked my friend what he would like on his hamburger, he said “What are the defaults?” The developers at the table knew what he meant but the waitress was very confused.
Aug 13, 2019 In the VB Editor's References dialog box, I can't seem to find the 'Microsoft Internet Controls' library. Has it been renamed to something else?
- The ExecWB method requires an OLE Command ID to be passed in to identify the command to execute. This value nCmdID is of type Long. The nCmdExecOpt parameter represents the value for the command execution option. Together, these values instruct the control as to what supported command to execute and what degree of user prompting should.
- Excel – Enable macros or ActiveX controls by default; reddit Q&A – How to extract data from HTML into Excel; Launch VBA code macro from a GO or RUN button; How to add VBA References – Internet Controls, HTML Object Library; VBA – Web scraping with getElementsByTagName How to remove your name and other meta info from an Excel file; Speed-write VBA code by recording a macro.
Like burgers, the WebBrowser control has a default configuration. By default, the WebBrowser control runs in compatibility view mode. Compatibility view mode is basically document mode 7.
Below is a screenshot of a simple .NET application using the web browser control.
The web page reports back the document mode and the user agent string received by the server. By default, the WebBrowser control sends a “IE 7” user agent string and renders the content using document mode “7”.
How do I Change the Default WebBrowser Document Mode?
If compatibility view does not render your content correctly, you have a couple of options. Depending on your scenario, you may need one or both of these options.
Compatibility Meta Tag
If you have control over the web sites or web pages that are being accessed by the web browser control, you can add compatibility meta tags to control the document mode. Below is a screenshot of the same WebBrowser control application displaying a page which includes <meta http-equiv='X-UA-Compatible'>.
The “IE=edge” causes the browser control to render the content in the highest available document mode. In this case, IE 11 is installed resulting in the content being displayed in document mode 11.
Note: The user agent string sent to the server in the request is IE 7. Be aware of this mismatch if you will also be browsing to the same content in the IE browser. The full IE browser would send an IE 11 user agent string unless the site was included in the compatibility view list. If your web page is doing browser sniffing via the user agent string, you could encounter rendering differences or errors.
The WebBrowser control can only support the document modes available for the installed browser version on the client. If the client has IE 8 installed, a compatibility meta tag with the value of “IE=10” would default to the highest mode available of 8. You could consider defining multiple document modes and allow the control to pick the highest available document mode. However, your content would need to render correctly in the different modes.
Here’s an example page with the following compatibility meta tag: <meta http-equiv='X-UA-Compatible'>
Here is the example app running on a client with IE 11 installed:
![Vba internet controls Vba internet controls](/uploads/1/2/4/8/124888256/835223069.jpg)
Because of the compatibility meta tag, the highest document mode specified “10” is chosen.
Here is the example app running on a client with IE 8 installed:
Since the highest available document mode is 8, the content is displayed in document mode 8.
FEATURE_BROWSER_EMULATION Registry Key
If you need to target a specific version of the browser, you may consider using the FEATURE_BROWSER_EMULATION registry key. This option may work for scenarios where you have a line of business application that has specific content such as help files or an internal web site. The registry key allows you to set a different default document mode for the WebBrowser control for a given application.
Note: Be careful when modifying the registry. You should only use this key for applications you compile. Modifying the behavior of an application you didn't create may affect the functionality of the application.
32-bit and 64-bit Complexities
You have the option to add the browser emulation key to the current user (HKCU) or the local machine ((HKLM) hive. If you add to the current user HKCU hive, you don’t need to worry about “bitness” of your OS or application. However, if you add the key to the local machine hive, you need to consider the following complexities. Depending on the “bitness” of your application, you need to add the key to the correct registry location on a Windows 64-bit machine. On a 64-bit OS, 32-bit applications run in the WOW64 subsystem. For 32-bit apps, WOW64 redirects registry calls to a separate location for certain keys. The FEATURE_BROWSER_EMULATION key is redirected. Therefore, on a 64-bit OS, a 32-bit application’s value needs to be placed in HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftInternet ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION.
In this case, we are always requesting the content to be displayed using document mode 10 and ignores the !DOCTYPE for the page.
If you’re wondering if your app is a 32-bit app running on a 64-bit OS, you can quickly verify by checking Task Manager.
32-bit applications running on a 64-bit OS will have “(32 bit)” after the name.
What’s the Difference Between a Setting that Ignores the !DOCTYPE and the One that Doesn’t?
When you pick one of the settings that ignore the !DOCTYPE, the user agent string matches the requested document mode. In the following example, the FEATURE_BROWSER_EMULATION value is 10000. This ignores the !DOCTYPE.
Note: The browser control sends a IE 10 user agent string.
If we choose a setting that looks for a standards doctype, the browser control sends the default standards based user agent string. In the following example, the FEATURE_BROWSER_EMULATION value is 10001.
Note: The browser control sends the default standards based user agent string. In this case, IE 11 is installed on the client. Therefore, the user agent string is an IE 11 user agent string.
What Happens if I Set the FEATURE_BROWSER_EMULATION Document Mode Value Higher than the IE Version on the Client?
Obviously, the browser control can only support a document mode that is less than or equal to the IE version installed on the client. Using the FEATURE_BROWSER_EMULATION key works best for enterprise line of business apps where there is a deployed and support version of the browser. In the case you set the value to a browser mode that is a higher version than the browser version installed on the client, the browser control will choose the highest document mode available.
Here is an example of setting the value to 9000 on a client that has IE 8 installed.
We can see that the browser control displays the content in the highest available document mode of 8.
Does the Compatibility View List or Enterprise Mode Affect the Behavior of the WebBrowser Control?
Compatibility View list and Enterprise mode are features of the full Internet Explorer (iexplore.exe). Therefore, the web browser control does not support the Compatibility View list or Enterprise mode.
Debugging Your WebBrowser Control App in Visual Studio
The FEATURE_BROWSER_EMULATION key values require the executable name. If you are debugging your app in Visual Studio, your app is being hosted in Visual Studio. Therefore, you need an entry for the host. Task manager details can help determine what the value should be named.
Based on this information, the app is 32-bit and the executable name is “EmbeddedIE.vshost.exe”. Therefore, the value needs to be added to Wow6432Node and name is “EmbeddedIE.vshost.exe”.
Otherwise, you will see different behavior when debugging verses launching the executable.
Using IE to Determine what Document Mode You Need
The Emulation F12 development tool is very handy for determining what document mode you might need for your content.
In IE, just press F12 and select the “Emulation” tool.
Using the Document mode setting, you can change the document mode to quickly see how the page would be rendered in a different mode. You can also change the User agent string to investigate how the server will respond to different user agent strings.
Introduction xxxiii
Part I: Introduction to Excel VBA 1
Chapter 1: Essentials of Spreadsheet Application Development 3
What Is a Spreadsheet Application? 3
Steps for Application Development 4
Determining User Needs 5
Planning an Application That Meets User Needs 6
Determining the Most Appropriate User Interface 7
Concerning Yourself with the End User 12
Other Development Issues 17
Chapter 2: Introducing Visual Basic for Applications 19
Getting a Head Start with the Macro Recorder 19
Working with the Visual Basic Editor 32
VBA Fundamentals 43
Deep Dive: Working with Range Objects 48
Essential Concepts to Remember 52
Don’t Panic–You Are Not Alone 54
Chapter 3: VBA Programming Fundamentals 61
VBA Language Elements: An Overview 61
Comments 63
Variables, Data Types, and Constants 65
Assignment Statements 76
Arrays 78
Declaring Arrays 78
Object Variables 80
User-Defined Data Types 81
Built-in Functions 82
Manipulating Objects and Collections 85
Controlling Code Execution 88
Chapter 4: Working with VBA Sub Procedures 105
About Procedures 105
Executing Sub Procedures 108
Passing Arguments to Procedures 119
Error-Handling Techniques 123
A Realistic Example That Uses Sub Procedures 127
Utility Availability 140
Evaluating the Project 141
Chapter 5: Creating Function Procedures 143
Sub Procedures vs. Function Procedures 143
Why Create Custom Functions? 144
An Introductory Function Example 144
Function Procedures 148
Function Arguments 153
Function Examples 153
Emulating Excel’s SUM Function 167
Extended Date Functions 170
Debugging Functions 172
Dealing with the Insert Function Dialog Box 173
Using Add-Ins to Store Custom Functions 178
Using the Windows API 178
Chapter 6: Understanding Excel’s Events 183
What You Should Know About Events 183
Getting Acquainted with Workbook-Level Events 189
Examining Worksheet Events 197
Monitoring with Application Events 206
Chapter 7: VBA Programming Examples and Techniques 217
Learning by Example 217
Working with Ranges 218
Working with Workbooks and Sheets 246
VBA Techniques 251
Some Useful Functions for Use in Your Code 258
Some Useful Worksheet Functions 263
Windows API Calls 278
Part II: Advanced VBA Techniques 287
Chapter 8: Working with Pivot Tables 289
An Introductory Pivot Table Example 289
Creating a More Complex Pivot Table 295
Creating Multiple Pivot Tables 299
Creating a Reverse Pivot Table 302
Chapter 9: Working with Charts 305
Getting the Inside Scoop on Charts 305
Creating an Embedded Chart 308
Creating a Chart on a Chart Sheet 309
Modifying Charts 309
Using VBA to Activate a Chart 310
Moving a Chart 311
Using VBA to Deactivate a Chart 312
Determining Whether a Chart Is Activated 313
Deleting from the ChartObjects or Charts Collection 313
Looping Through All Charts 314
Sizing and Aligning ChartObjects 317
Creating Lots of Charts 318
Exporting a Chart 321
Changing the Data Used in a Chart 322
Using VBA to Display Custom Data Labels on a Chart 328
Displaying a Chart in a UserForm 331
Understanding Chart Events 334
Discovering VBA Charting Tricks 340
Working with Sparkline Charts 347
Chapter 10: Interacting with Other Applications 351
Understanding Microsoft Office Automation 351
Automating Access from Excel 354
Automating Word from Excel 356
Automating PowerPoint from Excel 360
Automating Outlook from Excel 365
Starting Other Applications from Excel 369
Chapter 11: Working with External Data and Files 377
Working with External Data Connections 377
Power Query Basics 377
Using ADO and VBA to Pull External Data 390
Working with Text Files 397
Text File Manipulation Examples 401
Performing Common File Operations 405
Zipping and Unzipping Files 413
Part III: Working with UserForms 417
Chapter 12: Leveraging Custom Dialog Boxes 419
Alternatives to UserForms 419
Using an Input Box 419
Using the VBA MsgBox Function 426
Using the Excel GetOpenFilename Method 431
Using the Excel GetSaveAsFilename Method 434
Prompting for a Folder 435
Displaying Excel’s Built-in Dialog Boxes 435
Displaying a Data Form 438
Chapter 13: Introducing UserForms 441
How Excel Handles Custom Dialog Boxes 441
Inserting a New UserForm 442
Adding Controls to a UserForm 443
Toolbox Controls 443
Adjusting UserForm Controls 448
Adjusting a Control’s Properties 450
Displaying a UserForm 456
Closing a UserForm 458
Creating a UserForm: An Example 460
Referencing UserForm Controls 473
Customizing the Toolbox 474
Creating UserForm Templates 477
A UserForm Checklist 478
Chapter 14: Looking at UserForm Examples 479
Creating a UserForm “Menu” 479
Selecting Ranges from a UserForm 481
Creating a Splash Screen 483
Disabling a UserForm’s Close Button 486
Changing a UserForm’s Size 487
Zooming and Scrolling a Sheet from a UserForm 488
Exploring ListBox Techniques 490
Using the MultiPage Control in a UserForm 512
Using an External Control 513
Animating a Label 516
Chapter 15: Implementing Advanced UserForm Techniques 519
A Modeless Dialog Box 519
Displaying a Progress Indicator 523
Creating Wizards 534
Emulating the MsgBox Function 541
A UserForm with Movable Controls 545
A UserForm with No Title Bar 546
Simulating a Toolbar with a UserForm 548
Emulating a Task Pane with a UserForm 550
A Resizable UserForm 551
Handling Multiple UserForm Controls with One Event Handler 556
Selecting a Color in a UserForm 559
Displaying a Chart in a UserForm 561
Making a UserForm Semitransparent 562
A Puzzle on a UserForm 563
Video Poker on a UserForm 565
Part IV: Developing Excel Applications 567
Chapter 16: Creating and Using Add-Ins 569
What Is an Add-In? 569
Understanding Excel’s Add-in Manager 572
Creating an Add-In 574
An Add-In Example 575
Comparing XLAM and XLSM Files 581
Manipulating Add-Ins with VBA 587
Optimizing the Performance of Add-Ins 593
Special Problems with Add-Ins 594
Chapter 17: Working with the Ribbon 599
Ribbon Basics 599
Customizing the Ribbon 601
Creating a Custom Ribbon 606
Using VBA with the Ribbon 628
Creating an Old-Style Toolbar 632
Chapter 18: Working with Shortcut Menus 637
CommandBar Overview 637
Referring to Controls in a CommandBar 640
Properties of CommandBar Controls 641
Displaying All Shortcut Menu Items 642
Using VBA to Customize Shortcut Menus 644
Resetting a shortcut menu 646
Shortcut Menus and Events 654
Chapter 19: Providing Help for Your Applications 659
Help for Your Excel Applications 659
Help Systems That Use Excel Components 661
Displaying Help in a Web Browser 670
Using the HTML Help System 672
Chapter 20: Leveraging Class Modules 679
What Is a Class Module? 679
Creating a NumLock Class 681
Coding Properties, Methods, and Events 685
Exposing a QueryTable Event 688
Creating a Class to Hold Classes 692
Chapter 21: Understanding Compatibility Issues 699
What Is Compatibility? 699
Types of Compatibility Problems 699
Avoid Using New Features 701
But Will It Work on a Mac? 703
Dealing with 64-Bit Excel 704
Creating an International Application 705
Multilanguage Applications 707
VBA Language Considerations 708
Using Local Properties 708
Identifying System Settings 709
Date and Time Settings 711
Control Ie With Vba
Part V: Appendix 713
Appendix: VBA Statements and Functions Reference 715
Index 725