Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
To repeat, I want to copy a word from Word, paste it into the input field in the online dictionary, have the site return a result (OUTPUT), copy the output, and paste it back into Word on the next line after the word that was looked up.

The word to look up is in the language "Gurmukhi" but this is irrelevant.

The website (online dictionary) is here:

To test how it works, you can click the words in the left margin here (although one would normally type or paste the word into the input field at the above site):

There are two possible outputs depending on whether the word being looked up IS FOUND or NOT FOUND.

1) First Possibility: the word IS FOUND

START of OUTPUT string: The FOUND output string always STARTS with ANY ONE of 4 heading strings. These are:

4 Heading Strings
1) "SGGS Gurmukhi/Hindi to Punjabi-English/Hindi Dictionary"
2) "SGGS Gurmukhi-English Dictionary"
3) "English Translation"
4) "Mahan Kosh Encyclopedia"

The first 15 characters of each are as follows:
1) "SGGS Gurmukhi/H"
2) "SGGS Gurmukhi-E"
3) "English Transla"
4) "Mahan Kosh Ency"

END of OUTPUT string: the FOUND output string always ENDS just before the following string at the bottom of the page:
"Mahan Kosh data provided by Bhai Baljinder Singh (RaraSahib Wale); See"

To summarize:
When the word IS FOUND, the START and END of the OUTPUT string are as follows:
START: the first character of the first instance of ANY ONE of the above 4 heading strings
END: The character before the string (given above in full): "Mahan Kosh data provided by…"

2) Second Possibility: the word is NOT FOUND

This is an example of the output string when the word is not found:
"No search results found for ਅਵਗ. Please try another search."

To summarize:
When the word IS FOUND, the START and END of the OUTPUT string are as follows:
START: The string: "No search results found for"
END: the string "search."

So essentially, the string between and including "No" and "search.".

(note the middle part of the output string includes the word that was looked up)

What I have tried:

<pre>Sub Dictionary()	
'Here is the code I have written.
'The first and last part that deal with Word are fine.
'I need help on the demarcated middle part where it says:
	Dim CopyRange As Range
	Dim PasteRange As Range
	Dim LookUpWord As String
	Set CopyRange = ActiveDocument.Paragraphs(1).Range
	LookUpWord = CopyRange.Text
	Set PasteRange = ActiveDocument.Paragraphs(2).Range		
	Dim ie As Object
	Set ie = CreateObject("InternetExplorer.Application")
	ie.Visible = True
	ie.navigate ""
	Do While ie.Busy Or ie.readyState <> 4
	'Paste the word (variable: LookUpWord) into the input field
    	'at the website
	'get the result/output from the site
    	'(see explanation for what constitutes the OUTPUT)
    'copy the result	
	Dim OutputDefinition As String
	OutputDefinition = {contents of clipboard]	
	PasteRange = OutputDefinition	
End Sub
Updated 17-Mar-23 0:51am

1 solution

One of these should help you[^]
Automate Internet Explorer (IE) Using VBA - Automate Excel[^]
There are also several YouTube videos if you prefer that medium - all available with this this Google Search[^] "vba interact with website"
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900