html/text type conversion to Word styles

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

html/text type conversion to Word styles

Post by Robie »

Hi

Not sure how to ask this so I am just going give few examples. Basically, I need to convert text into Word paragraphs, i.e. read a text file and convert text into Word documents. Some examples below (I am still working on the ideas) that I have been given:

<H1>Heading row 1</H1>
<H2>Heading row Level 2</H2>
<H3>Heading row Level 3</H3>

<code>This is code so set the style to Courier New</code>
<b>Bold</b>
<i/Italic</i>
<u>underline</u>
or any combination of the above

A table that becomes a table in Word (something like this):
<TABLE>
<TR><TH>Type <TH>height<TH>weight<TH>Red eyes
<TR><TH>Males<TD>1.9<TD>0.003<TD>40%
<TR><TH>Females<TD>1.7<TD>0.002<TD>43%
</TABLE>

'* ' or '- ' becomes a bullet
'# ' becomes a numbered item

Do conversion scripts already exists for such a thing? Is there something that can take a table as defined above and create a table in Word?I Googled but not much joy. Any ideas highly appreciated.

Thanks.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: html/text type conversion to Word styles

Post by HansV »

You describe HTML format, so you only need to change the extension of the text file to .htm or .html and open it in Word. Word will take care of the conversion.

You can then AutoFormat the document, this will convert * and - at the beginning of a paragraph to bullets; you would only need to convert # to a numbered list.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: html/text type conversion to Word styles

Post by HansV »

Here is a macro that will replace "# " at the beginning of a paragraph with numbering. It may be slow for large documents.

Code: Select all

Sub FixNumbering()
  Dim par As Paragraph
  Dim rng As Range
  Application.ScreenUpdating = False
  For Each par In ActiveDocument.Paragraphs
    If Left(par.Range.Text, 2) = "# " Then
      par.Style = ActiveDocument.Styles(wdStyleListNumber)
      Set rng = par.Range
      rng.Collapse
      rng.Delete Unit:=wdCharacter, Count:=2
    End If
  Next par
  Application.ScreenUpdating = True
End Sub
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: html/text type conversion to Word styles

Post by Robie »

HansV wrote:You describe HTML format, so you only need to change the extension of the text file to .htm or .html and open it in Word. Word will take care of the conversion.

You can then AutoFormat the document, this will convert * and - at the beginning of a paragraph to bullets; you would only need to convert # to a numbered list.
Thanks Hans. Wow - out of the box thinking :0).

I think this idea of renaming the document as HTML may work for quite a lot of the changes needed. Rest, I can process manually (VBA).

I don't understand the AutoFormat bit though. How do I get that to work? Sorry, not at work to check out AutoFormat.

Really, really grateful Hans for a great idea. :clapping: :cheers:

Robie.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: html/text type conversion to Word styles

Post by HansV »

If you select Format | AutoFormat.... (in Word 2007 you have to add the AutoFormat option to the Quick Access Toolbar), Word will automatically format the document:
x81.png
You can specify which elements will be formatted in the AutoFormat options:
x82.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans