Talk:Microsoft Word Macros

Converting Embedded Images
--Rigolo 09:43, 29 March 2006 (UTC) says:

I encounter a lot of word documents that have embedded images in the text. When using these word macro's these images are "lost" and there is also no information in the converted document to identify where these images where in the text. So when you need to convert a lot of documents with embedded images it takes a long time to extract the images and place them correctly in the new wiki document.

I would like to propose the following:

In word you can save a document as HTML. This will create a seperate "folder" with all the embedded images as seperate PNG files. These images are numbered from 1 to n. This might be a quick way of converting all embedded images to files that can be uploaded to a wiki. The drawback is that the images are always numbered from 1 to n for each document and do not get a unique name.

This does not yet solve the reference to these images in the converted document. I noticed that you can use the VBA functions to select the embedded images. These images are either "Shape" objects or "InLineShapes". A function could be written that will loop through all the shapes in the document and replaces it with a tag where the could be a generic name based on the file-name and sequence number. This way you know at least where your images should be located in the wiki document. Than all that is left is upload the pictures to the wiki.

I also found a project that can extract the image information from a word document with the original resolution. This is code that was created by Stephen Lebans and can be found on his web page web page under the file section Word.zip

Table Conversion Update
A slightly different way of doing tables that takes colspanning into account. 207.93.211.186 00:40, 18 October 2005 (UTC)

' Convertion des tables Sub wp_wiki_tableau

Dim tableau As Table Dim aRange As Range

For Each tableau In ActiveDocument.Tables Dim i As Integer Dim j As Integer Dim totalCols As Integer Dim strCellSep As String ' keep the total rows in a separate variable for ' column spanning totalCols = tableau.Columns.Count For i = 1 To tableau.Rows.Count For j = 1 To tableau.Rows(i).Cells.Count Selection.Find.ClearFormatting '           ' First row will always be considered a header ' All other rows are tabular data. '           If i = 1 Then strCellSep = "!" Else strCellSep = "|" End If           ' ' possible column spanning '           If ((j = tableau.Rows(i).Cells.Count) And (j < totalCols)) Then 'irritatingly, the formatting separator is always a pipe tableau.Cell(i, j).Range.InsertBefore " colspan=" & totalCols - j + 1 & "|" End If           If j <= tableau.Rows(i).Cells.Count Then tableau.Cell(i, j).Range.InsertBefore strCellSep End If           If j = 1 Then If i = 1 Then tableau.Cell(i, j).Range.InsertBefore "{| border=1 cellspacing=0 " & vbCrLf Else tableau.Cell(i, j).Range.InsertBefore "|- " & vbCrLf End If           End If            If j < tableau.Rows(i).Cells.Count Then tableau.Cell(i, j).Range.InsertAfter " " & strCellSep End If       Next j '        tableau.Cell(i, tableau.Columns.Count).Range.InsertAfter vbCrLf & "|" Next i   tableau.Cell(tableau.Rows.Count, tableau.Columns.Count).Range.InsertAfter vbCrLf & "|} " Set aRange = tableau.ConvertToText(Separator:="*") aRange.Style = wdStylePlainText 'teste si une ligne a bien été laissée avant et après le tableau If aRange.Start > 2 Then If ActiveDocument.Characters(aRange.Start - 2) <> Chr(13) Then aRange.InsertBefore Chr(13) End If   End If '     If ActiveDocument.Characters(aRange.End + 1) <> Chr(13) Then '        aRange.InsertAfter Chr(13) '    End If Next tableau RemplaceSeparateurEtoile End Sub

Word2Wiki 2006-03-22
I had trouble getting other versions to work, so I cleaned this one up. Enjoy. -GaryLacey 20:56, 22 March 2006 (UTC) Sub Word2Wiki Application.ScreenUpdating = False ConvertHeading 1 ConvertHeading 2 ConvertHeading 3 ConvertHeading 4 ConvertHeading 5 ConvertItalic ConvertBold ConvertUnderline ConvertLists ConvertTables ActiveDocument.Content.Copy ' copy to clipboard Application.ScreenUpdating = True End Sub Private Sub ConvertHeading(aHeading As Integer) Dim normalStyle As Style Set normalStyle = ActiveDocument.Styles(wdStyleNormal) ActiveDocument.Select With Selection.Find .ClearFormatting .Style = ActiveDocument.Styles(-1 - aHeading) .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 newline characters ' 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 String(1 + aHeading, "=") .InsertAfter String(1 + aHeading, "=") 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 newline characters ' pick-up the rest with the next search .Font.Bold = False .Collapse .MoveEndUntil vbCr End If         ' don't bother to markup newline characters - prevent a loop 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 newline characters ' pick-up the rest with the next search .Font.Italic = False .Collapse .MoveEndUntil vbCr End If         ' don't bother to markup newline characters - prevent a loop 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 newline characters ' pick-up the rest with the next search .Font.Underline = False .Collapse .MoveEndUntil vbCr End If         ' don't bother to markup newline characters - prevent a loop 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 Dim i As Integer 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 Private Sub ConvertTables Dim aTable As Table Dim aRange As Range For Each aTable In ActiveDocument.Tables Set aRange = aTable.ConvertToText(Separator:=wdSeparateByTabs) With aRange .InsertBefore "!" ' header row ' convert rows to |- .Find.Execute _ FindText:="^p", _ ReplaceWith:="^p|-^p|", _ Format:=True, _ Replace:=wdReplaceAll, _ MatchControl:=True ' convert column tabs to || .Find.Execute _ FindText:="^t", _ ReplaceWith:="||", _ Format:=True, _ Replace:=wdReplaceAll, _ MatchControl:=True .InsertParagraphBefore .InsertBefore "{| class='wikitable'" .InsertAfter ("|}") ' fix last row .Find.Execute _ FindText:="^p|-^p||}", _ ReplaceWith:="^p|}", _ Format:=True, _ Replace:=wdReplaceOne, _ MatchControl:=True '.Select Selection.ClearFormatting End With Next aTable End Sub

Mediawiki -> Word converter?
It would be useful to have a converter the other way, in order to use Word as a WYSIWYG editor. Anyone know of such a thing? (if someone replies ages from now, a message on my talk page would be great.) Stevage 08:22, 22 May 2006 (UTC)

Can't convert
Greetings,

I have tried the macros to convert Word to MediaWiki, but I invariably get errors, with a numeric code (Word2Wiki) or without (compiler error､ "cant reduce argument" - Word2MediaWiki). I have a number tables with colspan and rowspan, plus some special character, like the "forced space" before colon or semicolon, which occurs in French documents.

Can somebody help? Thanks in advance. --Mahlerite 08:50, 3 February 2008 (UTC)