word to Tiddlywiki converter

765 views
Skip to first unread message

dotCdot

unread,
Jan 13, 2007, 5:44:39 PM1/13/07
to TiddlyWiki
I use this simple macro which is loaded into word to type up ttext then
copy and paste it into a tiddler.
it converts headers 1 to 5, bold, underline, italic, and numbered and
bulleted lists. I am not clever enough to do tables, maybe someone else
can do that :)

It is translated to TiddlyWiki from Word2Wiki by RobertCastley: as
posted onto WikiMedia's Meta-wiki page.
go to http://meta.wikimedia.org/wiki/Word_macros#Word2TWiki for the
original and the instructions there.

to use it, you must first load it as a word macro:
* copy the vba script below into a text editor and then save it as
Word2TiddlyWiki.bas
* Open your word document and then hit Alt+F11.
* Then select File -> Import File.
* Select the file you have just saved.
* Close the Visual Basic screen.
to run the macro:
* Block the text you want to convert
* Then in your Word document select Alt+F8.
* The converter will do its job and should automatically copy the
conversion into the clipboard.
* All you then need to do is to paste into your editor in
TiddlyWiki.

regards, ..c..

CODE FOLLOWS:

Sub Word2TiddlyWiki()

Application.ScreenUpdating = False

ConvertH1
ConvertH2
ConvertH3
ConvertH4
ConvertH5

ConvertItalic
ConvertBold
ConvertUnderline

ConvertLists
' ConvertTables ... could not get it to work :(

' Copy to clipboard
ActiveDocument.Content.Copy

Application.ScreenUpdating = True
End Sub

Private Sub ConvertH1()
Dim normalStyle As Style
Set normalStyle = ActiveDocument.Styles(wdStyleNormal)

ActiveDocument.Select

With Selection.Find

.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading1)
.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
.Collapse
.MoveEndUntil vbCr
End If

' Don't bother to markup newline characters (prevents a
loop, as well)
If Not .Text = vbCr Then
.InsertBefore "!"
End If

.Style = normalStyle
End With
Loop
End With
End Sub

Private Sub ConvertH2()
Dim normalStyle As Style
Set normalStyle = ActiveDocument.Styles(wdStyleNormal)

ActiveDocument.Select

With Selection.Find

.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading2)
.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
.Collapse
.MoveEndUntil vbCr
End If

' Don't bother to markup newline characters (prevents a
loop, as well)
If Not .Text = vbCr Then
.InsertBefore "!!"
End If

.Style = normalStyle
End With
Loop
End With
End Sub

Private Sub ConvertH3()
Dim normalStyle As Style
Set normalStyle = ActiveDocument.Styles(wdStyleNormal)

ActiveDocument.Select

With Selection.Find

.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading3)
.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
.Collapse
.MoveEndUntil vbCr
End If

' Don't bother to markup newline characters (prevents a
loop, as well)
If Not .Text = vbCr Then
.InsertBefore "!!!"
End If

.Style = normalStyle
End With
Loop
End With
End Sub
Private Sub ConvertH4()
Dim normalStyle As Style
Set normalStyle = ActiveDocument.Styles(wdStyleNormal)

ActiveDocument.Select

With Selection.Find

.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading3)
.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
.Collapse
.MoveEndUntil vbCr
End If

' Don't bother to markup newline characters (prevents a
loop, as well)
If Not .Text = vbCr Then
.InsertBefore "!!!!"
End If

.Style = normalStyle
End With
Loop
End With
End Sub
Private Sub ConvertH5()
Dim normalStyle As Style
Set normalStyle = ActiveDocument.Styles(wdStyleNormal)

ActiveDocument.Select

With Selection.Find

.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading3)
.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
.Collapse
.MoveEndUntil vbCr
End If

' Don't bother to markup newline characters (prevents a
loop, as well)
If Not .Text = vbCr Then
.InsertBefore "!!!!!"
End If

.Style = normalStyle
End With
Loop
End With
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

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 "//"
.InsertAfter "//"
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 "__"
.InsertAfter "__"
End If

.Font.Underline = False
End With
Loop
End With
End Sub

Private Sub ConvertLists()
Dim para As Paragraph
For Each para In ActiveDocument.ListParagraphs
With para.Range
.InsertBefore " "
For i = 1 To .ListFormat.ListLevelNumber
If .ListFormat.ListType = wdListBullet Then
.InsertBefore "*"
Else
.InsertBefore "#"
End If
Next i
.ListFormat.RemoveNumbers
End With
Next para
End Sub

Steve

unread,
Jan 21, 2007, 9:52:28 PM1/21/07
to TiddlyWiki
I attempted to install the macro as described in your post, but it
threw a compile error (Sub or Function not defined) around line 50
("characters"). Perhaps an error on my part, but perhaps you can
suggest a fix.(?) Thanks for the contribution, nonetheless.

Chris Lawley

unread,
Jan 22, 2007, 6:43:08 AM1/22/07
to Tiddl...@googlegroups.com

On 21 Jan 2007, Steve wrote:

> I attempted to install the macro as described in your post, but it
> threw a compile error (Sub or Function not defined) around line 50
> ("characters"). Perhaps an error on my part, but perhaps you can
> suggest a fix.(?) Thanks for the contribution, nonetheless.

That wouldn't be because some lines have wrapped incorrectly in the
email thus throwing parts of comment lines into lines of their own
and so making them appear to Word to be instructions it can't make
head nor tail of?

chris :-)


dotCdot

unread,
Jan 22, 2007, 10:45:35 AM1/22/07
to TiddlyWiki
yes, that looks like the problem.
I will eyescan against the original and note revert with the
differences ...
however, it does look as if it is the comment lines (the ones with a
single quote mark to start with) that is causing the problem

If someone can tell me how, I will upload the .bas file and it can then
be downloaded

dotCdot

unread,
Jan 22, 2007, 11:48:55 AM1/22/07
to TiddlyWiki
The longer comments are indeed broken
Every instance of:-

' Just process the chunk before any newline
characters

-and-

' Don't bother to markup newline characters (prevents a
loop, as well)

must become a single line again.
You can fix it inside the macro (comments are green lines so they are
easy to find.)
Position your cursor at the end of the offending line and hit the
delete button to bring it back to where it should be.

:)
..c..

Steve

unread,
Jan 25, 2007, 6:59:36 PM1/25/07
to TiddlyWiki
Worked like a charm! Thank you again for the prompt and thoughtful
response.
Reply all
Reply to author
Forward
0 new messages