Consulting

Results 1 to 2 of 2

Thread: Formatting my Word Document as an HTML

  1. #1

    Formatting my Word Document as an HTML

    Hi,

    I am trying to format my word document to include HTML "tags". In the context of word, it is useless, but I will be copying this text and posting it in a HTML Text box.

    I have 2 separate macros. and I wan't to add a third function.

    But I also want to combine all three into one macro so that I don't have to run all three, I can just run one.

    The function I don't have that I want to add, is the addition of <p> at the start of each paragraph, and have </p> at the end.

    And I'd also like to know how I can combine these 3 functions into one macro.

    HTML Tags:
    Sub HTMLTag()'
    ' HTMLTag Macro
    
    
    Selection.Find.Style = ActiveDocument.Styles("Emphasis")
    With Selection.Find
        .Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .ClearFormatting
        .Font.Bold = True
        With .Replacement
          .ClearFormatting
          .Text = "<b>^&</b>"
          .Font.Bold = False
        End With
        .Execute Replace:=wdReplaceAll
        .ClearFormatting
        .Font.Italic = True
        With .Replacement
          .ClearFormatting
          .Text = "<i>^&</i>"
          .Font.Italic = False
        End With
        .Execute Replace:=wdReplaceAll
        .ClearFormatting
        .Font.Underline = True
        With .Replacement
          .ClearFormatting
          .Text = "<u>^&</u>"
          .Font.Underline = False
        End With
        .Execute Replace:=wdReplaceAll
    End With
    
    End Sub
    HTML Breaks:
    Sub HTMLBreak()
    '
    ' HTMLBreak Macro
    
    Selection.Find.Style = ActiveDocument.Styles("Emphasis")
    With Selection.Find
        .Text = "***"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .ClearFormatting
        .Font.Bold = False
        With .Replacement
          .ClearFormatting
          .Text = "<hr/>"
          .Font.Bold = False
        End With
        .Execute Replace:=wdReplaceAll
    End With
    
    End Sub
    Thank you so much!

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Try:
    Sub ApplyHTMLTags()
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = ""
        .Replacement.Text = "<b>^&</b>"
        .Forward = True
        .Format = True
        .Font.Bold = True
        .Replacement.Font.Bold = False
        .Wrap = wdFindContinue
        .MatchWildcards = False
        .Execute Replace:=wdReplaceAll
        .ClearFormatting
        .Replacement.Text = "<i>^&</i>"
        .Font.Italic = True
        .Replacement.Font.Italic = False
        .Execute Replace:=wdReplaceAll
        .ClearFormatting
        .Font.Underline = True
        .Replacement.Text = "<u>^&</u>"
        .Replacement.Font.Underline = False
        .Execute Replace:=wdReplaceAll
        .ClearFormatting
        .Text = "***"
        .Replacement.Text = "<hr/>"
        .Execute Replace:=wdReplaceAll
        .Text = "^p"
        .Replacement.Text = "</p>^p<p>"
        .Execute Replace:=wdReplaceAll
      End With
      .InsertBefore "<p>"
      .Paragraphs.Last.Range.Delete
    End With
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

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
  •