Private Sub Workbook_Open() Const strExceltoWiki As String = "Copy Selection to Wiki" Dim myButton As CommandBarButton Dim Wb As Workbook Dim I As Integer 'Check in current Tools menu if item already exist For I = 1 To Application.CommandBars("Tools").Controls.Count If Application.CommandBars("Tools").Controls(I).Caption = strExceltoWiki Then Exit Sub End If Next I Set myButton = Application.CommandBars("Tools").Controls.Add(Type:=msoControlButton, temporary:=True) myButton.Caption = strExceltoWiki myButton.Style = msoButtonCaption myButton.BeginGroup = True myButton.OnAction = "ThisWorkbook.SelectionToWiki" '"DieseArbeitsmappe.SelectionToWiki" for german users. End Sub Public Sub SelectionToWiki() ' Macro to convert/export the selected cells into a DokuWiki table ' Tested with DokuWiki 2010-11-07 ' Limitations: ' won't format individual characters within a cell Dim currentSelection As Range, thisCell As Range Dim wikiText As String, thisCellText As String Dim rows As Integer, cols As Integer, thisRow As Integer, thisCol As Integer Dim inMerge As Boolean Dim oData As Object Set oData = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'Instantiate DataObject without FM 2.0. Set currentSelection = ActiveWindow.RangeSelection rows = currentSelection.rows.Count cols = currentSelection.Columns.Count wikiText = "" For thisRow = 1 To rows inMerge = False For thisCol = 1 To cols Set thisCell = currentSelection.Cells(thisRow, thisCol) 'value thisCellText = thisCell.Value 'if it's an empty cell then make it a space (to avoid merging cells) If Not inMerge And thisCellText = "" Then thisCellText = " " If Not inMerge Then 'replace Dokuwiki syntax signs thisCellText = Replace(thisCellText, "*", "%%*%%") thisCellText = Replace(thisCellText, "|", "%%|%%") thisCellText = Replace(thisCellText, "^", "%%^%%") 'Convert the FIRST hyperlink of the cell & add the cell content as the hyperlink's name If thisCell.Hyperlinks.Count > 0 Then thisCellText = " [[" & thisCell.Hyperlinks(1).Address & "|" & thisCellText & "]] " End If 'don't apply formatting and alignment for cells within a merged area (only the first cell gets that) 'formatting With thisCell.Font If .Bold = True Then thisCellText = "**" & thisCellText & "**" If .Italic = True Then thisCellText = "//" & thisCellText & "//" If .Underline <> xlUnderlineStyleNone Then thisCellText = "__" & thisCellText & "__" End With 'alignment Select Case thisCell.HorizontalAlignment Case xlLeft thisCellText = thisCellText & " " Case xlRight thisCellText = " " & thisCellText Case xlCenter thisCellText = " " & thisCellText & " " End Select End If 'check for merged cells If thisCell.MergeCells Then inMerge = True End If 'replace embedded newlines with backslashes thisCellText = Replace(thisCellText, Chr(10), "\\ ") 'add this cell to wiki output string If thisRow = 1 Or thisCell.Interior.ColorIndex <> xlNone Then 'heading row or colored cell wikiText = wikiText & "^" & thisCellText Else wikiText = wikiText & "|" & thisCellText End If Next thisCol 'end this row If thisRow = 1 Or thisCell.Interior.ColorIndex <> xlNone Then 'heading row or colored cell wikiText = wikiText & "^" & Chr(13) Else wikiText = wikiText & "|" & Chr(13) End If Next thisRow 'now copy to clipboard oData.SetText (wikiText) oData.PutInClipboard MsgBox "Selected cells were copied into clipboard", vbInformation End Sub