#1
|
|||
|
|||
HTML Class to Word Styles
Hi all,
Not so sure this belongs here, but some cluey person might have an answer. I have an HTML file that is being imported into MS Word. e.g. Code:
Set oDoc = oApp.documents.add oDoc.Range.InsertFile = "C:MyPath\MyFile.htm" On that import, any text recognised as a Header (e.g. 'H1') is automatically applied to the Heading 1 style. Awesome... except... ...any other text is converted into the Normal style. So I tried to be clever and set the class of the HTML tag. e.g. Code:
<p style='Font-Family:Tahoma,Geneva, sans-serif' Class='Body Text">My Paragraph</p> So... how might I address this problem? |
#2
|
||||
|
||||
I had a fiddle with this and had some clues after exporting a Word doc in HTML format and looking at that output. As a result I found that you can import styles like this
Code:
<p Class=MsoBodyText>Body Text Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p> <p Class=MsoList>List Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p> <p Class=MsoListNumber>List Number Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p> <p Class=MsoHeading1>Heading 1 Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p> <p Class=MsoTitle>Heading 2 Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p> For instance most of these above worked but the p Class=MsoHeading1 created a new style called msoheading1. This is not the end of the world since I should have used H1 instead of p anyway.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Oh this is magic. Thanks Andrew.
Much appreciated. |
#4
|
||||
|
||||
Note that you can also make use of style aliases to 'force' a tagged paragraph into a specific style when you don't know its built-in MsoXXX title
For instance, if I wanted to make any of these map to a specific style in Word then I could firstly add them as stylename aliases in Word and then import the html. In the case of the Heading 1 style in Word, change the stylename in your Word doc to "Heading 1,random,fubar" which means you can then import the following html lines which all become Heading 1 in the document. Code:
<p Class=random>Heading 1 Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p> <p Class=fubar>Heading 1 Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</p> <h1>Heading 1 Vestibulum ut diam magna. Maecenas ut interdum ante, vel volutpat nibh</h1>
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Okay, awesome. This is great followup information.
I am in fact writing from an Access webbrowser control to word. This functionality is fine - VBA. It happens that after I tested how this works (thanks to your response) I discovered that I would have to assign the classes to each paragraph in the html before importing - which I didn't think about until after the fact. My guess is that I will have to do some string manipulation to find and replace <p> tags with <P Class="msoBodyText">Ect...</p>". although I think there's a way to change attributes... but not yet sure where this rabbit hole will go. In any case, this info you've given is very valuable, and much appreciated. Thanks tons! |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Displaying in the Styles Pane Only the Styles You Actually Use -- Which Was a Snap in Word 2003 | RobertB | Word | 4 | 08-09-2022 09:29 AM |
Turn off an Initialized Class | ilcaa72 | Word VBA | 3 | 05-01-2017 07:13 PM |
Self-created styles in Word to appear when converting to HTML | anapat | Word | 2 | 05-11-2013 09:40 PM |
Evernote--Class Notes | markg2 | Outlook | 0 | 05-10-2012 05:50 PM |
Can you actually write HTML and CSS in a word document and send it as an html page | jackaroo | Word | 0 | 07-12-2010 07:49 AM |