VBA HTML - creating a hyperlink

musicgold

Board Regular
Joined
Jan 9, 2008
Messages
197
I am using a VBA macro to populate the pages of a flashcard website.

In one of the text fields, I need to enter a URL. When I do this task manually, as soon as paste the URL in the field and press enter, the URL turns into a hyperlink. So when I review the flashcard later, I can click on the URL and open the relevant web page in another tab.

However when I use the following code to populate that field, the URL doesn't become a hyperlink, but remains text. Is there way I can ensure that the URL becomes a hyperlink?

Thank

VBA Code:
htmlDoc.getElementById("Front").innertext = String1
htmlDoc.getElementById("Back").innertext = "https://www.history.com/topics/china/genghis-khan"
htmlDoc.getElementById("GoNextcard").Click
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Reasoned guess, but still a guess:

Possibly by adding vbCrLf

htmlDoc.getElementById("Back").innertext = "Genghis Khan" & vbCrLf

or vbCr or vbLf

Provide a link to the webpage and more of your code if the above did not work.
 
Upvote 0
Reasoned guess, but still a guess:

Possibly by adding vbCrLf

htmlDoc.getElementById("Back").innertext = "Genghis Khan" & vbCrLf

or vbCr or vbLf

Provide a link to the webpage and more of your code if the above did not work.

Thanks.
I tried the following code but it didn't work. It seems the Innertext property doesn't recognize the vbCrLf character.

VBA Code:
htmlDoc.getElementById("Back").innertext = "https://www.history.com/topics/china/genghis-khan" & vbCrLf

The flashcard site is "About - AnkiWeb" . You will need to create a login.
I am adding a screenshot of the page I am working on.


1598642171232.png
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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