HMTL to Word in VBA

JohnnyNitro

New Member
Joined
Jan 9, 2015
Messages
1
I'm trying to scrape a website for a specific HTML element and convert it into Word, all while keeping the formatting intact. I can successfully import it into Excel first (and then to Word), but the character limit for a single cell doesn't let me grab all of the data that I need. Here is my current code, starting at the point where I grab the HTML from the site:

Code:
Set html = ie.document

Dim objWord As Object
   Dim objDoc As Object
   Set objWord = CreateObject("Word.Application")
   Set objDoc = objWord.Documents.Add
   objWord.Visible = True


Sheets("Sheet1").Range("A1").Value = html.getElementById("main_container").innerText
Sheets("Sheet1").Range("A1").Select
Selection.Copy


objDoc.Range.Paste

It would be great if I could skip the Excel step and just paste the HTML right into Word. The other option that I thought of is to paste each sub-paragraph of the main_container HMTL into a separate cell to avoid hitting the maximum character limit. If anyone can help with that, or has other ideas about how I can solve this, it would be much appreciated!

Cross-post here: http://stackoverflow.com/questions/27854534/how-do-i-insert-hmtl-to-word-using-vba
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,217,364
Messages
6,136,115
Members
449,993
Latest member
Sphere2215

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