VBA HTML - creating a hyperlink

musicgold

Board Regular
Joined
Jan 9, 2008
Messages
180
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
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,881
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.
 

musicgold

Board Regular
Joined
Jan 9, 2008
Messages
180
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,409
Messages
5,595,973
Members
414,035
Latest member
billbumkins

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
Top