Microsoft Office Tutorials and References
In Depth Information
Try It
The code associated with this UserForm is surprisingly simple. Double-click the UserForm
to access its module. In the Object drop-down list, select UserForm and in the Procedure
drop-down list select Initialize. The Initialize event is a single line of code that tells the
WebBrowser which website to navigate to when the UserForm initializes, similar to the
homepage setting on your web browser. In this example, I entered the website for
Here is the entire Initialize event with that navigation command:
Private Sub UserForm_Initialize()
WebBrowser1.Navigate “”
End Sub
You have an Exit button named cmdExit , so use the Unload Me command for that:
Private Sub cmdExit_Click()
Unload Me
End Sub
Regarding the CommandButton for navigation, the process will start by the user entering a
website address in the TextBox. The user can then either click the cmdNavigate button, or
press the Enter key because you set the Default property to True for the cmdNavigate
button in Step 8. Thinking ahead for more convenience, you can structure the cmdNavigate’s
Click event to assume that all web addresses start with “http://www.”, which will save the
user time and effort by just entering the web address’s domain name. For example, instead of
entering in the TextBox, a user need only enter
with this code for the cmdNavigate button:
Private Sub cmdNavigate_Click()
WebBrowser1.Navigate “http://www.” & TextBox1.Text
End Sub
All that’s left are the two buttons for Back and Forward, easily handled with the WebBrowser
control’s GoBack and GoForward methods. For both methods, On Error Resume Next is
utilized to avoid a run time error if the browsing session is at its starting or ending point
when the cmdBack or cmdForward button is clicked. Here is the code for GoBack :
Private Sub cmdBack_Click()
On Error Resume Next
End Sub
Here is GoForward :
Private Sub cmdForward_Click()
On Error Resume Next
End Sub
When you call the UserForm, Figure 20-12 shows an example that is similar to what
you will see.
Search JabSto ::

Custom Search