F
Fai Vapiwalla
Hi All,
I've come across the "The Word2BBCode-Converter ... written on June 2,
2006 by Matthew Kruer" VBA script which works amazingly. I've read
other posts that say it has some issues with coloured text but since I
only use it for converting Bold, Underline, and Italics to BBcode it
is fine.
What I can't figure out is how to modify that code to only convert a
selection to bbcode, and not the whole document. I just want to be
able to (hastily) select a paragraph of text that i can see has some
bolding in it, hit a hotkey combination (that has the word to bbcode
macro attached to it) and have the bolding turned into bbcode. What
part of the below code should I modify, and to what?
The first part of Kruer's code (that deals with converting all
document bolding to bbcode) looks like this:
'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 ""
.InsertAfter ""
End If
.Font.Bold = False
End With
Loop
End With
End Sub
I've come across the "The Word2BBCode-Converter ... written on June 2,
2006 by Matthew Kruer" VBA script which works amazingly. I've read
other posts that say it has some issues with coloured text but since I
only use it for converting Bold, Underline, and Italics to BBcode it
is fine.
What I can't figure out is how to modify that code to only convert a
selection to bbcode, and not the whole document. I just want to be
able to (hastily) select a paragraph of text that i can see has some
bolding in it, hit a hotkey combination (that has the word to bbcode
macro attached to it) and have the bolding turned into bbcode. What
part of the below code should I modify, and to what?
The first part of Kruer's code (that deals with converting all
document bolding to bbcode) looks like this:
'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 ""
.InsertAfter ""
End If
.Font.Bold = False
End With
Loop
End With
End Sub