Option Explicit Sub SelectionToWiki() ' Macro to convert/export the selected cells into a DokuWiki table ' Tested with DokuWiki 2007-06-26 ' 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 DataObject Set oData = New DataObject Set currentSelection = ActiveWindow.RangeSelection rows = currentSelection.rows.Count cols = currentSelection.Columns.Count wikiText = "" For thisRow = 1 To rows If thisRow = 1 Then 'heading row wikiText = wikiText & "^" Else wikiText = wikiText & "|" End If 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 '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 'add this cell to wiki output string If thisRow = 1 Then 'heading row wikiText = wikiText & thisCellText & "^" Else wikiText = wikiText & thisCellText & "|" End If Next thisCol 'end this row wikiText = wikiText + Chr(13) Next thisRow 'now copy to clipboard oData.SetText (wikiText) oData.PutInClipboard MsgBox "Selected cells were copied into clipboard", vbInformation End Sub