Bible Research Tools Discussion Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

The Bible Research Tools Discussion Forum is now online!

Pages: [1]

Author Topic: Word Macro to assist in formatting  (Read 188 times)

Administrator

  • Administrator
  • Senior Member
  • *****
  • Posts: 115
    • View Profile
    • Bible Research Tools
Word Macro to assist in formatting
« on: January 01, 2018, 11:34:21 AM »

This Microsoft Word Macro will automatically convert Word and RTF document formats to the 'Bold', 'Italic' and 'Indent' BBC Codes. 'Indent' conversions apply only to italicized paragraphs, which must begin with a double-quote (").

The 'Underline' format will also be converted to BBC Codes. However, any 'Bold' formatting inside an 'Underline' format will be lost.  'Underline' formats inside 'Bold' formatting will both convert.

The macro can be assigned to a hot-key, such as Alt-F12, for even faster formatting.

' ==================================================
Sub FormatForBRTForum()
Dim i As Long, txt As String
 
    ' -- modify 'Underline'
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    With Selection.Find.Font
         .Underline = True
    End With
    With Selection.Find
        Do While .Execute(FindText:="", Forward:=True, MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
            With Selection
                 txt = .Text
                .Text = "[" & "u]" & txt & "[" & "/u]"
                .Font.Underline = False
                .Collapse wdCollapseEnd
        End With
         Loop
    End With
 
    ' -- modify 'Bold'
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    With Selection.Find.Font
         .Bold = True
    End With
    With Selection.Find
        Do While .Execute(FindText:="", Forward:=True, MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
            With Selection
                 txt = Trim$(.Text)
                .Text = "[" & "b]" & txt & "[" & "/b]"
                .Font.Bold = False
                .Collapse wdCollapseEnd
        End With
         Loop
    End With

    ' -- change Italic paragraphs to 'Italics and Indent'
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    With Selection.Find.Font
         .Italic = True
    End With
    With Selection.Find
        Do While .Execute(FindText:="", Forward:=True, MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
            With Selection
                txt = Trim$(.Text)
                If Left$(txt, 1) = Chr$(34) Then
                    .Text = "[" & "left-indent][" & "i]" & txt & "[" & "/i][" & "/left-indent]"
                    .Font.Italic = False
                    .Collapse wdCollapseEnd
                End If
            End With
         Loop
    End With
   
    ' -- reformat 'End Italic' Code
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p[" & "/i]"
        .Replacement.Text = "[" & "/i]"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    ' -- reformat 'End Indent' Code
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "[" & "/left-indent]"
        .Replacement.Text = "[" & "/left-indent]^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    ' -- modify random 'Italics'
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    With Selection.Find.Font
         .Italic = True
    End With
    With Selection.Find
        Do While .Execute(FindText:="", Forward:=True, MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
            With Selection
                 txt = .Text
                .Text = "[" & "u]" & txt & "[" & "/u]"
                .Font.Italic = False
                .Collapse wdCollapseEnd
        End With
         Loop
    End With
   
    ' -- Reformat line breaks, part 1
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = "^p^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    ' -- Reformat line breaks, part 2
    For i = 1 To 3
        Selection.HomeKey wdStory
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "^p^p^p"
            .Replacement.Text = "^p^p"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    Next i
   
End Sub
' ==================================================

Dan

« Last Edit: January 09, 2018, 03:59:47 PM by Administrator »
Logged

FaithIsKey

  • Regular Member
  • **
  • Posts: 36
    • View Profile
Re: Word Macro to assist in formatting
« Reply #1 on: January 01, 2018, 11:52:55 PM »



This Microsoft Word Macro will automatically format posts with the 'Bold', 'Italic' and 'Indent' BBC Codes.


Thanks, Dan.  That is very helpful! 

Faith

Logged

Matt712

  • New Member
  • *
  • Posts: 14
  • Partial Preterist
    • View Profile
Re: Word Macro to assist in formatting
« Reply #2 on: January 05, 2018, 04:55:09 PM »


This Microsoft Word Macro will automatically format posts with the 'Bold', 'Italic' and 'Indent' BBC Codes.


Dan, do you have anything like this for Open Office?

Matt

Logged

Administrator

  • Administrator
  • Senior Member
  • *****
  • Posts: 115
    • View Profile
    • Bible Research Tools
Re: Word Macro to assist in formatting
« Reply #3 on: January 08, 2018, 06:37:50 PM »


Dan, do you have anything like this for Open Office?


Matt,

I took a look at it, hoping I could import Word macros. But there are too many differences. I use Open Office to create the Research Library help files because their PDF export is more flexible, with a simple setup. But there is a learning curve for their macro Basic language.

Dan


Logged

Administrator

  • Administrator
  • Senior Member
  • *****
  • Posts: 115
    • View Profile
    • Bible Research Tools
Re: Word Macro to assist in formatting
« Reply #4 on: January 09, 2018, 04:05:35 PM »


UPDATE!

The Word Macro has been updated to eliminate the need to modify the brackets. The macro should operate correctly with a simple copy/paste. An explanation of the requirements for accurate 'Underline" conversions is also included.

Dan


Logged
Pages: [1]