Hi all,
I wrote a simple export macro for creating a table in Excel and
exporting the selection in Tiddlywiki syntax (a modification of this
script:
http://www.lacher.com/examples/a960521b.htm). It could be
improved by copying data to the clipboard rather than writing to a
file.
Todd
Rem ***** BASIC *****
Sub TiddlyWikiExport()
' Dimension all variables
Dim DestFile As String
Dim FileNum As Integer
Dim ColumnCount As Integer
Dim RowCount As Integer
Dim Clipboard As String
' Prompt user for destination filename
DestFile = InputBox("Enter the destination filename" _
& Chr(10) & "(with complete path):", "Quote-Comma Exporter")
' Obtain next free file handle number
FileNum = FreeFile()
' Turn error checking off
On Error Resume Next
' Attempt to open destination file for output
Open DestFile For Output As #FileNum
' If an error occurs report it and end
If Err <> 0 Then
MsgBox "Cannot open filename " & DestFile
End
End If
' Turn error checking on
On Error GoTo 0
' Loop for each row in selection
For RowCount = 1 To Selection.Rows.Count
' Write the initial table tag
Print #FileNum, "|";
' Loop for each column in selection
For ColumnCount = 1 To Selection.Columns.Count
' Write the background color tag
If Selection.Cells(RowCount, ColumnCount).Interior.Color <>
vbWhite Then
ColorToRGB CStr(Selection.Cells(RowCount,
ColumnCount).Interior.Color), r, g, b
Print #FileNum, "bgcolor(#" & r & g & b & "): ";
End If
' Write the initial bold tag
If Selection.Cells(RowCount, ColumnCount).Font.Bold = True
Then
Print #FileNum, "''";
End If
' Write the initial italics tag
If Selection.Cells(RowCount, ColumnCount).Font.Italic = True
Then
Print #FileNum, "//";
End If
' Write the initial strikethrough tag
If Selection.Cells(RowCount, ColumnCount).Font.Strikethrough =
True Then
Print #FileNum, "---";
End If
' Set right alignment
If Selection.Cells(RowCount, ColumnCount).HorizontalAlignment
= xlRight Or _
Selection.Cells(RowCount, ColumnCount).HorizontalAlignment
= xlCenter Then
Print #FileNum, " ";
End If
' Write the initial font color tag
If Selection.Cells(RowCount, ColumnCount).Font.Color <>
vbBlack Then
ColorToRGB CStr(Selection.Cells(RowCount,
ColumnCount).Font.Color), r, g, b
Print #FileNum, "@@color(#" & r & g & b & "):";
End If
' Write the initial hyperlink tag
If Selection.Cells(RowCount, ColumnCount).Hyperlinks.Count > 0
Then
Print #FileNum, "[[";
End If
' Write current cell's text
Print #FileNum, Selection.Cells(RowCount, ColumnCount).Text;
' Write the initial hyperlink tag
If Selection.Cells(RowCount, ColumnCount).Hyperlinks.Count > 0
Then
Print #FileNum, "|" & Selection.Cells(RowCount,
ColumnCount).Hyperlinks(1).Address & "]]";
End If
' Write the ending font color tag
If Selection.Cells(RowCount, ColumnCount).Font.Color <>
vbBlack Then
Print #FileNum, "@@";
End If
' Set left alignment
If Selection.Cells(RowCount, ColumnCount).HorizontalAlignment
= xlLeft Or _
Selection.Cells(RowCount, ColumnCount).HorizontalAlignment
= xlCenter Then
Print #FileNum, " ";
End If
' Write the ending strikethrough tag
If Selection.Cells(RowCount, ColumnCount).Font.Strikethrough =
True Then
Print #FileNum, "---";
End If
' Write the ending italic tag
If Selection.Cells(RowCount, ColumnCount).Font.Italic = True
Then
Print #FileNum, "//";
End If
' Write the ending bold tag
If Selection.Cells(RowCount, ColumnCount).Font.Bold = True
Then
Print #FileNum, "''";
End If
' Write the ending table separator
Print #FileNum, "|";
' Check if cell is in last column
If ColumnCount = Selection.Columns.Count Then
' If so then write a blank line
Print #FileNum,
End If
' Start next iteration of ColumnCount loop
Next ColumnCount
' Start next iteration of RowCount loop
Next RowCount
'Close destination file
Close #FileNum
End Sub
Sub ColorToRGB(ByVal Color As String, ByRef r, ByRef g, ByRef b)
On Error GoTo Solution
Dim SStr As String
SStr = "000000" & Hex(Color)
SStr = Right(SStr, 6)
b = Mid(SStr, 1, 2)
g = Mid(SStr, 3, 2)
r = Mid(SStr, 5, 2)
If Len(r) < 2 Then r = "0" & r
If Len(g) < 2 Then g = "0" & g
If Len(b) < 2 Then b = "0" & b
Solution:
If Err.Number <> 0 Then
r = -1
g = -1
b = -1
End If
End Sub