Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inserting HTML tags into Word document

    I've got several hundred word documents that I need to do some formatting on. I need to go through them and insert html tags into the document as per below...

    a short bold text line

    becomes

    a short < b >bold text< / b > line

    At the moment I really only need bold, italic, underline, and unordered lists.

    Does anyone know of the easiest and most efficient way of doing this? (Or some macro code?)

    I don't have much experience in Word, but currently looking at writing a macro.
    Last edited by Norto23; 2012-05-17 at 21:31. Reason: new line

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Norto,

    Welcome to the lounge as a new poster!

    You don't need to do anything except to format the document then save it as a Web page in the save dialog.
    WordAsWeb.JPG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    New Lounger
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    <b>, <i> etc inserted.

    Thanks for the reply. I still want the page to be in Word format, just want the tags <b>, <i> etc inserted.

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Cross-posted (and comprehensively answered) at: http://www.techsupportforum.com/foru...nt-646040.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Quote Originally Posted by Norto23 View Post
    Thanks for the reply. I still want the page to be in Word format, just want the tags <b>, <i> etc inserted.
    Since it uses Save As just change the file name slightly for the one with the tags.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    RetiredGeek: I think you need to differentiate here between converting a document to HTML format and adding code tags to a document. They're quite different things - your approach creates HTML files from the Word documents; it doesn't add tags to the text in a document. The OP says clearly "I still want the page to be in Word format". Telling the OP to "just change the file name slightly for the one with the tags" isn't going to help - it'll still be an HTML file, not a Word file.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #7
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts
    The bold, italic, and underlined could be done through replace, which could be made into a macro if you wanted.
    I don't know how I would do the unordered lists, though.

    One alternative would be to save your document as htm (filtered) and then in your browser read the source code. Copy that back into your Word document. Word produces a lot of html junk, though, for your purposes.
    Charles Kyle Kenyon
    Madison, Wisconsin

  8. #8
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts
    Unordered lists (bullets or nothing before the text) do present a problem unless styles are used for the lists. For the paragraph styles List Bullet and List, one could look for consecutive instances of the style; insert <li> (for list item)at the beginning of each paragraph and </li> at its end; and put the unordered list open and close tags (<ul> and </ul>) around the group.
    AFAIK, you can't search for bulleted paragraphs made using the the toolbar buttons of W2003 and before. But can VBA find them? In W20007/10, lists made using the ribbon buttons are in the List Paragraph style and can be searched for. But is there a way in VBA to tell whether the paragraph is preceded by a number or a bullet?

    Not being a VBA person, laying out these few possibilities is as far as I can go.

    Pam
    Last edited by PamCaswell; 2012-05-19 at 21:01.

  9. #9
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by Charles Kenyon View Post
    The bold, italic, and underlined could be done through replace, which could be made into a macro if you wanted.
    All of that is comprehensively addressed in the cross-post, with a macro!!!
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  10. #10
    New Lounger
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks

    hi guys

    thanks for the responses, the find and replace worked well!

    cheers

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •