Guest

Todd Chambery

By: a guest on Jan 3rd, 2008  |  syntax: VisualBasic  |  size: 4.91 KB  |  hits: 394  |  expires: Never
download  |  raw  |  embed  |  report abuse
This paste has a previous version, view the difference. Copied
  1. Rem  *****  BASIC  *****
  2. Sub TiddlyWikiExport()
  3.  
  4.     ' Dimension all variables
  5.    Dim TableData As String
  6.     Dim ColumnCount As Integer
  7.     Dim RowCount As Integer
  8.     Dim ClipboardData As New DataObject
  9.        
  10.     ' Loop for each row in selection
  11.    For RowCount = 1 To Selection.Rows.Count
  12.        
  13.         ' Write the initial table tag
  14.        TableData = TableData & "|"
  15.    
  16.         ' Loop for each column in selection
  17.        For ColumnCount = 1 To Selection.Columns.Count
  18.  
  19.         ' Do header formatting for the first row
  20.        If RowCount = 1 Then
  21.             TableData = TableData & "!"
  22.         Else
  23.        
  24.             ' Write the background color tag
  25.            If Selection.Cells(RowCount, ColumnCount).Interior.Color <> vbWhite Then
  26.                 ColorToRGB CStr(Selection.Cells(RowCount, ColumnCount).Interior.Color), r, g, b
  27.                 TableData = TableData & "bgcolor(#" & r & g & b & "): "
  28.             End If
  29.    
  30.             ' Write the initial bold tag
  31.            If Selection.Cells(RowCount, ColumnCount).Font.Bold = True Then
  32.                 TableData = TableData & "''"
  33.             End If
  34.    
  35.             ' Write the initial italics tag
  36.            If Selection.Cells(RowCount, ColumnCount).Font.Italic = True Then
  37.                 TableData = TableData & "//"
  38.             End If
  39.    
  40.             ' Write the initial strikethrough tag
  41.            If Selection.Cells(RowCount, ColumnCount).Font.Strikethrough = True Then
  42.                 TableData = TableData & "---"
  43.             End If
  44.    
  45.             ' Set right alignment
  46.            If Selection.Cells(RowCount, ColumnCount).HorizontalAlignment = xlRight Or _
  47.                 Selection.Cells(RowCount, ColumnCount).HorizontalAlignment = xlCenter Then
  48.                 TableData = TableData & " "
  49.             End If
  50.            
  51.             ' Write the initial font color tag
  52.            If Selection.Cells(RowCount, ColumnCount).Font.Color <> vbBlack Then
  53.                 ColorToRGB CStr(Selection.Cells(RowCount, ColumnCount).Font.Color), r, g, b
  54.                 TableData = TableData & "@@color(#" & r & g & b & "):"
  55.             End If
  56.            
  57.             ' Write the initial hyperlink tag
  58.            If Selection.Cells(RowCount, ColumnCount).Hyperlinks.Count > 0 Then
  59.                 TableData = TableData & "[["
  60.             End If
  61.         End If
  62.        
  63.         ' Write current cell's text
  64.        content = Replace(Selection.Cells(RowCount, ColumnCount).Text, Chr$(10), "<br>")
  65.         TableData = TableData & content
  66.        
  67.         If RowCount <> 1 Then
  68.            
  69.            ' Write the initial hyperlink tag
  70.           If Selection.Cells(RowCount, ColumnCount).Hyperlinks.Count > 0 Then
  71.                TableData = TableData & "|" & Selection.Cells(RowCount, ColumnCount).Hyperlinks(1).Address & "]]"
  72.            End If
  73.        
  74.            ' Write the ending font color tag
  75.           If Selection.Cells(RowCount, ColumnCount).Font.Color <> vbBlack Then
  76.                TableData = TableData & "@@"
  77.            End If
  78.            
  79.            
  80.            ' Set left alignment
  81.           If Selection.Cells(RowCount, ColumnCount).HorizontalAlignment = xlLeft Or _
  82.                Selection.Cells(RowCount, ColumnCount).HorizontalAlignment = xlCenter Then
  83.                TableData = TableData & " "
  84.            End If
  85.        
  86.            ' Write the ending strikethrough tag
  87.           If Selection.Cells(RowCount, ColumnCount).Font.Strikethrough = True Then
  88.                TableData = TableData & "---"
  89.            End If
  90.        
  91.            ' Write the ending italic tag
  92.           If Selection.Cells(RowCount, ColumnCount).Font.Italic = True Then
  93.                TableData = TableData & "//"
  94.            End If
  95.            
  96.            ' Write the ending bold tag
  97.           If Selection.Cells(RowCount, ColumnCount).Font.Bold = True Then
  98.                TableData = TableData & "''"
  99.            End If
  100.         End If
  101.        
  102.         ' Write the ending table separator
  103.        TableData = TableData & "|"
  104.        
  105.         ' Check if cell is in last column
  106.        If ColumnCount = Selection.Columns.Count Then
  107.             ' If so then write a blank line
  108.            TableData = TableData & Chr$(10)
  109.         End If
  110.  
  111.         ' Start next iteration of ColumnCount loop
  112.        Next ColumnCount
  113.  
  114.     ' Start next iteration of RowCount loop
  115.    Next RowCount
  116.    
  117.     ' Copy data to the clipboard
  118.    ClipboardData.SetText TableData
  119.     ClipboardData.PutInClipboard
  120. End Sub
  121.  
  122. Sub ColorToRGB(ByVal Color As String, ByRef r, ByRef g, ByRef b)
  123.  
  124. On Error GoTo Solution
  125. Dim SStr As String
  126. SStr = "000000" & Hex(Color)
  127. SStr = Right(SStr, 6)
  128. b = Mid(SStr, 1, 2)
  129. g = Mid(SStr, 3, 2)
  130. r = Mid(SStr, 5, 2)
  131.  
  132. If Len(r) < 2 Then r = "0" & r
  133. If Len(g) < 2 Then g = "0" & g
  134. If Len(b) < 2 Then b = "0" & b
  135.    
  136. Solution:
  137.     If Err.Number <> 0 Then
  138.         r = -1
  139.         g = -1
  140.         b = -1
  141.     End If
  142. End Sub