Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,066
- Office Version
- 2016
- Platform
- Windows
Hi
I am opening a url from a textbox. So when then button is clicked, the IE will open and display whichever url is in the textbox. The code works fine only the first time. If I close the IE and then add a new url into the textbox. When I click the button again I get the first error message on the code show below. To resolve this, I then added a bit more code but the error just moved to another part of the code. I can not seem to work this out
First Error Message
Error on this line of code
I added this bit of code, hoping it would get rid on the error
I now get this error message on the code below.
thanks
I am opening a url from a textbox. So when then button is clicked, the IE will open and display whichever url is in the textbox. The code works fine only the first time. If I close the IE and then add a new url into the textbox. When I click the button again I get the first error message on the code show below. To resolve this, I then added a bit more code but the error just moved to another part of the code. I can not seem to work this out
VBA Code:
Private Sub UrlsBrowserOpenBt_click()
'urls browser button
'This search will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
'Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
URL = [B]UrlsSearchTextBox1.Value[/B]
'Navigate to URL
IE.navigate URL
' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
Do While IE.readyState = 4: DoEvents: Loop 'Do While
Do Until IE.readyState = 4: DoEvents: Loop 'Do Until
'Webpage Loaded
Application.StatusBar = URL & " Loaded"
'Unload IE
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub
First Error Message
Error on this line of code
I added this bit of code, hoping it would get rid on the error
VBA Code:
On Error Resume Next
Set IE = CreateObject("InternetExplorer.Application")
On Error GoTo 0
I now get this error message on the code below.
thanks