Results 1 to 5 of 5
  1. #1
    A.Rubin
    Guest

    Limited SaveAs HTML

    What I'd like to do is (probably in a VBA Macro) is convert only the bold and italic fonts into the corresponding HTML, so I can spellcheck offline before posting to a web site which allows only those HTML commands. This is probably easy, but I've made several attempts and (The default SaveAs HTML does NOT produce an acceptable document.) I've come up with one which usually works unless the entire document is in boldface or italics, but sometimes goes into an infinite loop.

    Word version is Word 97 SR-2.

  2. #2
    A.Rubin
    Guest

    Re: Limited SaveAs HTML

    Let's try this again: What I have is the following macro set...<pre>Sub ToHTML()

    Dim R As Range
    Dim OK As Boolean

    Set R = ActiveDocument.Content

    With R.Find
    .ClearFormatting
    .Font.Bold = True
    .Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    Do
    If (Not .Execute) Then Exit Do
    R.InsertBefore ("")
    R.InsertAfter ("
    ")
    R.Font.Bold = False
    R.MoveEnd (wdStory)

    Loop

    R.Expand (wdStory)
    .ClearFormatting
    .Format = True
    .Font.Italic = True
    Do
    If (Not .Execute) Then Exit Do
    R.InsertBefore ("")
    R.InsertAfter ("
    ")
    R.Font.Italic = False
    R.MoveEnd (wdStory)

    Loop
    End With
    End Sub

    Sub FromHTML()
    Dim R As Range
    Dim OK As Boolean

    Set R = ActiveDocument.Content

    R.Find.ClearFormatting
    With R.Find
    .ClearFormatting
    .Text = "*"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    Do
    If (Not .Execute) Then Exit Do
    R.Text = ActiveDocument.Range(R.Start + 3, R.End - 4).Text
    R.Bold = True
    R.MoveEnd (wdStory)
    Loop

    R.Expand (wdStory)
    .Text = "*"
    Do
    If (Not .Execute) Then Exit Do
    R.Text = ActiveDocument.Range(R.Start + 3, R.End - 4).Text
    R.Italic = True
    R.MoveEnd (wdStory)

    Loop
    End With

    End Sub
    </pre>


    The problem: ToHTML seems to get into an indefinite loop. What am I doing wrong?

    (Should this be in the VB/VBA forum -- it is Word-specific, but....)

  3. #3
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Limited SaveAs HTML

    Hi Arthur,

    I ran your ToHTML code on a document with 2000 alternating Bold/Regular paragraphs without a hitch. Maybe it's just taking longer than you expect? (It took me about a minute with that doc.)

    Chris

  4. #4
    A.Rubin
    Guest

    Re: Limited SaveAs HTML

    Great ... I write about it (without having made any changes), and it works now. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Well, almost: if the entire document is bold and/or italics, <font face="Comic Sans MS">ToHTML</font face=comic> doesn't find anything. I added a simple patch to insert a non-bold non-italic space before the loops, and deleting it afterward.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Limited SaveAs HTML

    I'd like to inhibit Word97SR2 conversion of some less-than signs to $lt.

    I have some java script (a news feed) which I'd like to Include in a Word document then save the document as html. Word insists on converting the angle-brackets around strings like "javescarip".

    Have you do any further work on supplementing Word97's add-in converter?

Posting Permissions

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