Search: Home | Atlas | Guides | Tests | Research | Techs | Skills | Index | Recent Changes | Preferences | Login

Users > Isetnefret > Macro > Excel-To-Wiki

Excel to Wiki

Every page related to viticulture that I have pretty much came from Excel, and uses a macro to convert into a format the Wiki recognizes. Doing this by hand is......insane.

This simple macro well export the area of a worksheet that is selected and will export it to a file. It will prompt you to enter a file and path name. Be sure that you name it .txt, because that's the easiest. Make sure you put it somewhere you can find it.

Then open the text file and copy the contents into the Wiki. You have to play with it a little bit, but I think you'll like it.

Macro Code

Sub WikiExport()
   ' Dimension all variables.
   Dim DestFile As String
   Dim FileNum As Integer
   Dim ColumnCount As Integer
   Dim RowCount As Integer

   ' Prompt user for destination file name.
   DestFile = InputBox("Enter the destination filename" _
      & Chr(10) & "(with complete path):", "WikiExporter")

   ' 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

      ' Loop for each column in selection.
      For ColumnCount = 1 To Selection.Columns.Count

         ' Write current cell's text to file with quotation marks.
         Print #FileNum, "||  " & Selection.Cells(RowCount, _
            ColumnCount).Text & "  ";

         ' Check if cell is in last column.
         If ColumnCount = Selection.Columns.Count Then
            ' If so, then write a blank line.
            Print #FileNum, "||"
         Else
            ' Otherwise, write a comma.
            '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

Instructions

Have you ever created an Excel Macro before?

To use the Macro

Problems

Let me know if you have any problems

NameCreatorDateSizeDescription
WikiMacro.xlsIsetnefretJanuary 28, 2007 10:42 pm30720Export Excel Pages to Wiki Format
step11.gifIsetnefretJanuary 28, 2007 11:16 pm12719step 11
step3.gifIsetnefretJanuary 28, 2007 11:11 pm31548Step 3
step4.gifIsetnefretJanuary 28, 2007 11:13 pm8585step 4
step5.gifIsetnefretJanuary 28, 2007 11:14 pm2436step 5
step6.gifIsetnefretJanuary 28, 2007 11:14 pm13224step 6
step8.gifIsetnefretJanuary 28, 2007 11:16 pm16784step 8
step9.gifIsetnefretJanuary 28, 2007 11:16 pm55149step 9
ustep1.gifIsetnefretJanuary 28, 2007 11:16 pm2577Usage step 1
ustep3.gifIsetnefretJanuary 28, 2007 11:17 pm10549Usage step 3
ustep4.gifIsetnefretJanuary 28, 2007 11:17 pm12767Usage step 4

Home | Atlas | Guides | Tests | Research | Techs | Skills | Index | Recent Changes | Preferences | Login
You must log in to edit pages. | View other revisions
Last edited January 29, 2007 12:04 am by Isetnefret (diff)
Search: