To be honest I will provide you with a macro script for MS Word, which is not written by me, and it was taken from the phpBB community Word to BBcode Macro. This Visual Basic BBCode converter is really useful when you have CMS which is using BBCode, but in the same time does not provide enough options for easy management. Then every text you write, must be gone trough and where you have bold, italic, bolditalic, URL,
, must be surrounded with the correct BB code. This is rather annoying especially when you want to mark frequently different keyword for your SEO.
The Word2BBCode-Converter is written on June 2, 2006 by Matthew Kruer,as some parts are adapted from \”Word2Wiki-Converter\”. Major improvements were made by Gunter Schmidt.
The BBCode converter works with MS Word XP,2000 and above. The current license is GPL, which means that you are free to use and modify, but you have to keep the credits and do not sell.
-
'Word2BBCode-Converter v0.1
-
-
Sub Word2BBCode()
-
-
Application.ScreenUpdating = False
-
-
ConvertItalic
-
ConvertBold
-
ConvertUnderline
-
ConvertHyperlinks
-
-
ActiveDocument.Content.Copy
-
-
Application.ScreenUpdating = True
-
End Sub
-
Private Sub ConvertBold()
-
ActiveDocument.Select
-
-
With Selection.Find
-
-
.ClearFormatting
-
.Font.Bold = True
-
.Text = ""
-
-
.Format = True
-
.MatchCase = False
-
.MatchWholeWord = False
-
.MatchWildcards = False
-
.MatchSoundsLike = False
-
.MatchAllWordForms = False
-
-
.Forward = True
-
.Wrap = wdFindContinue
-
-
Do While .Execute
-
With Selection
-
If InStr(1, .Text, vbCr) Then
-
' Just process the chunk before any newline characters
-
' We'll pick–up the rest with the next search
-
.Font.Bold = False
-
.Collapse
-
.MoveEndUntil vbCr
-
End If
-
-
' Don't bother to markup newline characters (prevents a loop, as well)
-
If Not .Text = vbCr Then
-
.InsertBefore "[b]"
-
.InsertAfter "[/b]"
-
End If
-
-
.Font.Bold = False
-
End With
-
Loop
-
End With
-
End Sub
-
Private Sub ConvertItalic()
-
ActiveDocument.Select
-
-
With Selection.Find
-
-
.ClearFormatting
-
.Font.Italic = True
-
.Text = ""
-
-
.Format = True
-
.MatchCase = False
-
.MatchWholeWord = False
-
.MatchWildcards = False
-
.MatchSoundsLike = False
-
.MatchAllWordForms = False
-
-
.Forward = True
-
.Wrap = wdFindContinue
-
-
Do While .Execute
-
With Selection
-
If InStr(1, .Text, vbCr) Then
-
' Just process the chunk before any newline characters
-
' We'll pick-up the rest with the next search
-
.Font.Italic = False
-
.Collapse
-
.MoveEndUntil vbCr
-
End If
-
-
' Don't bother to markup newline characters (prevents a loop, as well)
-
If Not .Text = vbCr Then
-
.InsertBefore "[i]"
-
.InsertAfter "[/i]"
-
End If
-
-
.Font.Italic = False
-
End With
-
Loop
-
End With
-
End Sub
-
Private Sub ConvertUnderline()
-
ActiveDocument.Select
-
-
With Selection.Find
-
-
.ClearFormatting
-
.Font.Underline = True
-
.Text = ""
-
-
.Format = True
-
.MatchCase = False
-
.MatchWholeWord = False
-
.MatchWildcards = False
-
.MatchSoundsLike = False
-
.MatchAllWordForms = False
-
-
.Forward = True
-
.Wrap = wdFindContinue
-
-
Do While .Execute
-
With Selection
-
If InStr(1, .Text, vbCr) Then
-
' Just process the chunk before any newline characters
-
' We'll pick–up the rest with the next search
-
.Font.Underline = False
-
.Collapse
-
.MoveEndUntil vbCr
-
End If
-
-
' Don't bother to markup newline characters (prevents a loop, as well)
-
If Not .Text = vbCr Then
-
.InsertBefore "[u]"
-
.InsertAfter "[/u]"
-
End If
-
-
.Font.Underline = False
-
End With
-
Loop
-
End With
-
End Sub
-
-
Private Sub ConvertHyperlinks()
-
'converts Hyperlinks
-
'24–MAY-2006: only convert http…, mark others with error marker
-
-
Dim hyperCount&
-
Dim i&
-
Dim addr$ ', title$
-
-
hyperCount = ActiveDocument.Hyperlinks.Count
-
-
For i = 1 To hyperCount
-
-
With ActiveDocument.Hyperlinks(1) 'must be 1, since the delete changes count and position
-
-
addr = .Address
-
If Trim$(addr) = "" Then addr = "no hyperlink found"
-
'title = .Range.Text
-
-
'http, ftp
-
If LCase(Left$(addr, 4)) = "http" Or LCase(Left$(addr, 3)) = "ftp" Then
-
.Delete 'hyperlink
-
.Range.InsertBefore "[url=" & addr & "]"
-
.Range.InsertAfter "[/url]"
-
-
GoTo ConvertHyperlinks_Next
-
End If
-
-
'mailto:
-
If LCase(Left$(addr, 7)) = "mailto:" Then
-
.Delete 'hyperlink
-
.Range.InsertBefore "[email]" & addr & " "
-
.Range.InsertAfter "[/email]"
-
-
GoTo ConvertHyperlinks_Next
-
End If
-
-
'file guess
-
If Len(addr) > 4 Then 'the reason for not nice goto
-
If Mid$(addr, Len(addr) – 3, 1) = "." Then
-
.Delete
-
.Range.InsertBefore "[file://" & Replace(addr, " ", "_") & " "
-
.Range.InsertAfter "]"
-
-
GoTo ConvertHyperlinks_Next
-
End If
-
End If
-
-
'unidentified
-
.Delete
-
.Range.InsertBefore UnableToConvertMarker & "[" & addr & " "
-
.Range.InsertAfter "]"
-
-
ConvertHyperlinks_Next:
-
End With
-
-
Next i
-
-
End Sub
Copy the Word to BBCode converter, from the above field and save it as a .bas file(for example w2bb.bas).
To load the script, open your MS Word and expand the Macro section where you will find the Visual Basic editor.
Import the script from File -> Import File.
Once the Word to BBCode converter is imported either click ‘F5′, or go to ‘Run’ and then click ‘Run Macro’.
Then go back to MS Word and you will see your document converted.
The script is working perfect for me.
There is only one bug that happens, but I have not reported it yet since I am not sure what causing it. I think on a specific hidden character it just cannot end the \"while\" cycle.
The only resolution is to copy and paste the text in Notepad and then in a clean MS Word document. Unfortunately you will loose any formatting made.

