Microsoft Office Tutorials and References
In Depth Information
Try It
15.
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 wrox.com.
Here is the entire Initialize event with that navigation command:
Private Sub UserForm_Initialize()
WebBrowser1.Navigate “http://www.wrox.com”
End Sub
16.
You have an Exit button named cmdExit , so use the Unload Me command for that:
Private Sub cmdExit_Click()
Unload Me
End Sub
17.
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 http://www.somewhere.com in the TextBox, a user need only enter somewhere.com
with this code for the cmdNavigate button:
Private Sub cmdNavigate_Click()
WebBrowser1.Navigate “http://www.” & TextBox1.Text
End Sub
18.
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
WebBrowser1.GoBack
Err.Clear
End Sub
Here is GoForward :
Private Sub cmdForward_Click()
On Error Resume Next
WebBrowser1.GoForward
Err.Clear
End Sub
19.
When you call the UserForm, Figure 20-12 shows an example that is similar to what
you will see.
Search JabSto ::




Custom Search