Porting Word2MediaWikiPlus to VB.NET: Part 2

[This series has two previous articles: the prologue and Part 1.]

Initial source code examination

So I figured I’d get right into it.  I opened up Word 2003, went into the Tools > Macro > Macros… menu, and thinking there’d be some obvious Import function, hit the Organizer button.  No such luck, so I tried again via Tools > Macro > Visual Basic Editor, muddled around for a few minutes, and eventually just imported all the files via the File > Import File… menu option.

I don’t know much about how VBA multi-file applications are organized, but I figured that the one listed under the Class Modules folder would likely be the right one to start — Classes are the basic building block for all OO programs, right?

I had a quick look through the Sub’s defined in Class Modules > ThisDocument1 (which must correspond to the ThisDocument.cls file), and thought, “heh, this’ll be easy — there’s only a couple hundred lines of code and a handful of Sub’s”:

  • cmdCopyModuls_Click()
  • CreateSymbol()
  • CreateSymbol2()
  • CopyModulesToNormal()
  • cmdSymbols_Click()
  • cmdUninstall_Click()

Ah, but wait: there’s _Click() routines in them thar hills…which means there’s Form UI to deal with, and now that I look more closely, those .BAS files ended up as a list of entries under the Modules folder.


Yipes!  There’s a few more complicated questions to deal with than I’d originally thought.  For example, modW2MWP_FileDialog contains at least some code with a copyright heading, which could make life a bit tougher:

'***************** Code Start **************
'This code was originally written by Ken Getz.
'It is not to be altered or distributed, except as part of an application.
'You are free to use it in any application, provided the copyright notice is left unchanged.
' Code courtesy of:
' Microsoft Access 95 How-To
' Ken Getz and Paul Litwin
' Waite Group Press, 1996

This may not be so bad though, as the Functions in this module referring to file operations (e.g. GetOpenFile(), ahtCommonFileOpenSave())may be superfluous with the System.IO namespace available in VSTO.  We might not need these file I/O functions, though TestIt(), ahtAddFilterItem(), TriumNull() and TrimTrailingNull() may be needed.This brings up a really good point that I’ve seen mentioned in a couple of places, including John R. Durant’s blog from two years ago:

The real issue I see in migrating from VBA to VSTO is not the language or switching to a new runtime. […]  The more important factor is how the migration will affect the architecture of the application.  It is important to ask questions like: Does the new runtime make it possible for me to code this differently at a more fundamental level?  Can I cut lots of code? […]

This’ll be a fine line for me to walk: I’d like to make the conversion as quickly as possible, but it may not always be easy to figure out what the original code was meant to do.  It doesn’t help matters that many of the Comments in the source code are in German — as much as I’d like to think I can still understand German, it’s been sixteen years since I was in Germany and I’m more than a little rusty.  Hopefully the online German-to-English dictionaries will be able to sort out the gist of it.


The module modW2MWP_Registry is almost entirely focused on Registry interactions (which are well represented by the Microsoft.Win32.Registry class) except for the Uninstall_Word2MediaWikiPlus() Sub.  However, any necessary code has a more appropriate home in the VSTO add-in’s ThisAddIn_Shutdown() Sub.


This “module” is a monster — it’s a wonder it hasn’t been broken down into a whole namespace of classes — or I suppose in the VBA world, the closest they have is “a set of Modules” [no hierarchy.]  And it’s the central code:

‘ Function: Converts a word document to the wiki syntax

Anyway, it has a great deal of functionality — I’ll dig into it later.  This’ll be the majority of the work here.


This module is much smaller than modWord2MediaWikiPlus, but has some interesting functionality as well.  After studying them for a bit, I think I’ve figured out what general category of purpose each of them has:

Filesystem functions

Process functions

Text functions


Oh, and a DisplayError() for good measure.


I think I’m ready to start digging through the code in modWord2MediaWikiPlus – wish me luck!

Join us again — same Bat time, same Bat channel!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s