Explore Object Document Error

Dossfm0q

Banned User
Joined
Mar 9, 2009
Messages
570
Office Version
  1. 2019
Platform
  1. Windows
VBA Code:
Public Sub Test1()

' From english to Arab
    For i = 1 To 2
    Cells(i, 2) = Translate_Text(Cells(i, 1), "en", "ar")
    Next
End Sub
Public Sub Test2()

' From Arab to english
    For i = 1 To 2
    Cells(i, 2) = Translate_Text(Cells(i, 1), "ar", "en")
    Next

 End Sub


Function Translate_Text(txt_to_conv As String, Optional str_from As String, Optional str_to As String) As String

'Variable declaration
 Dim IE As Object, i As Long
 Dim Doc As Object
 Dim inputstring As String
 Dim outputstring As String
 Dim text_to_convert As String
 Dim result_data As String
 Dim str_Data As Variant

 'Create instance of IE
 Set IE = CreateObject("InternetExplorer.application")

        Set Doc = CreateObject("htmlfile")
       Set Doc = IE.document' err
 inputstring = str_from

 'Output language
 outputstring = str_to

 'Text to be converted
 text_to_convert = txt_to_conv

 'Open website
 IE.Visible = False
 IE.navigate "http://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text_to_convert

 Do Until IE.ReadyState = 4
     DoEvents
 Loop

 'Pause the code for 5 seconds
 Application.Wait (Now + TimeValue("0:00:5"))

 Do Until IE.ReadyState = 4
     DoEvents
 Loop
result_data = Doc .getElementsByid("myList").innerHTML
'or 
result_data = IE.document.getElementsByid("myList").innerHTML
'result_data = IE.document.IHTMLDocument3_getElementById("myList").innerHTML

 str_Data = Split(WorksheetFunction.Substitute(result_data, "</SPAN>", ""), "<")

 result_data = vbNullString
 For j = LBound(str_Data) To UBound(str_Data)
     result_data = result_data & Right(str_Data(j), Len(str_Data(j)) - InStr(str_Data(j), ">"))
 Next

 'Close IE
 IE.Quit
 Set IE = Nothing

 Translate_Text = result_data
End Function
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
any help

VBA Code:
Function openIE()

  Dim IE As Object, Doc As Object
 'Create instance of IE
 Set IE = CreateObject("InternetExplorer.application")
 Set Doc = IE.document
 
End Function
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top