Is it possible for MS Word to apply pasted HTML tags?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Is it possible for MS Word to apply pasted HTML tags?

  1. #1
    Join Date
    Sep 2006
    Posts
    32

    Question Is it possible for MS Word to apply pasted HTML tags?

    Suppose you paste this line to Word 2003:
    <b>ABC</b>
    Is it possible that word will make ABC bold and delete the two tags?
    AYK, many forum editors do exactly that.
    Appreciate any help.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: Is it possible for MS Word to apply pasted HTML tags?

    Well this has nothing to do with VB or programming and the obvious question is did you try it?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    Re: Is it possible for MS Word to apply pasted HTML tags?

    Pretty sure Word 2003 has SAVE AS HTML (probably two choices. try each). It will convert BOLD into html tags
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Sep 2006
    Posts
    32

    Re: Is it possible for MS Word to apply pasted HTML tags?

    A. I thought a VBA macro might be needed
    B. Of course, I am asking because I couldn't solve it myself.
    Thanks.

  5. #5
    Join Date
    Sep 2006
    Posts
    32

    Re: Is it possible for MS Word to apply pasted HTML tags?

    Saving is no problem. The reverse, ie reading text with HTML, is.
    Thanks.

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: Is it possible for MS Word to apply pasted HTML tags?

    Word 2003 can read HTML, so I can imagine an approach of saving (or writing by means of VBA) your HTML snippet to a temporary plain text file, then again open it with Word as HTML and copy-paste the now formatted text to the desired destination. However, that does not work with your sample HTML snippet from post #1 as-is. You'd probably need to wrap it into a proper HTML skeleton to turn it into a valid HTML file.

    Another approach I can think of is simply just supporting a small subset of HTML, interpret the tags yourself and apply the formatting in your VBA code. Shouldn't be too complicated either, but of course the effort largely depends on how extensive you want your HTML support to be.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  7. #7
    Join Date
    Sep 2006
    Posts
    32

    Re: Is it possible for MS Word to apply pasted HTML tags?

    Quote Originally Posted by Eri523 View Post
    Word 2003 can read HTML, so I can imagine an approach of saving (or writing by means of VBA) your HTML snippet to a temporary plain text file, then again open it with Word as HTML and copy-paste the now formatted text to the desired destination. However, that does not work with your sample HTML snippet from post #1 as-is. You'd probably need to wrap it into a proper HTML skeleton to turn it into a valid HTML file.

    Another approach I can think of is simply just supporting a small subset of HTML, interpret the tags yourself and apply the formatting in your VBA code. Shouldn't be too complicated either, but of course the effort largely depends on how extensive you want your HTML support to be.
    Please show me how Word can save and read HTML. I couldn't locate HTML in "Save As" list.
    Thanks for attention.

  8. #8
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: Is it possible for MS Word to apply pasted HTML tags?

    I am using Word 2002 under the file menu is Save As which has the following options web page *.htm|*.html, web page filtered, web archive, rich text and so on
    There is also a save as web page on the file menu just below the save as.
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: Is it possible for MS Word to apply pasted HTML tags?

    Quote Originally Posted by Bruin 1953 View Post
    Please show me how Word can save and read HTML. I couldn't locate HTML in "Save As" list.
    Saving has already been explained by DataMiser. However, taking the approach I suggested, you wouldn't save as HTML anyway, instead you would save as plain text (i.e. unformatted). Opening an HTML file using Word's GUI works more or less the same as saving; just pick "Web Pages" as the file type to open.

    Programmatically opening an HTML file would be done using a VBA command like this one:

    Code:
    Documents.Open FileName:="Test.htm", ConfirmConversions:=False, AddToRecentFiles:=False, Format:=wdOpenFormatWebPages
    For a properly formed HTML file, automatic format detection (Format:=wdOpenFormatAuto) would probably work as well.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center