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.
html/text type conversion to Word styles
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: html/text type conversion to Word styles
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.
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
Hans
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: html/text type conversion to Word styles
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
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: html/text type conversion to Word styles
Thanks Hans. Wow - out of the box thinking :0).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.
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.
Robie.
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: html/text type conversion to Word styles
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:
You can specify which elements will be formatted in the AutoFormat options:
You can specify which elements will be formatted in the AutoFormat options:
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans