Attachment 'word2wiki.bas'

Download

   1 Attribute VB_Name = "Word2Wiki"
   2 
   3 Sub Word2Wiki()
   4     
   5     Application.ScreenUpdating = False
   6 
   7     RemoveHyperlinks
   8 
   9     ConvertH1
  10     ConvertH2
  11     ConvertH3
  12     
  13     ConvertItalic
  14     ConvertBold
  15     ConvertUnderline
  16     
  17     ConvertLists
  18     ConvertTables
  19     
  20     EscapeSpecialChar
  21     
  22     ' Copy to clipboard
  23     ActiveDocument.Content.Copy
  24     
  25     Application.ScreenUpdating = True
  26 End Sub
  27 
  28 Private Sub RemoveHyperlinks()
  29 	Dim oField As Field
  30 	For Each oField In ActiveDocument.Fields
  31 		If oField.Type = wdFieldHyperlink Then
  32 			oField.Unlink
  33 		End If
  34 	Next
  35 	Set oField = Nothing
  36 End Sub
  37 
  38 Private Sub ConvertH1()
  39     Dim normalStyle As Style
  40     Set normalStyle = ActiveDocument.Styles(wdStyleNormal)
  41     
  42     ActiveDocument.Select
  43     
  44     With Selection.Find
  45     
  46         .ClearFormatting
  47         .Style = ActiveDocument.Styles(wdStyleHeading1)
  48         .Text = ""
  49         
  50         .Format = True
  51         .MatchCase = False
  52         .MatchWholeWord = False
  53         .MatchWildcards = False
  54         .MatchSoundsLike = False
  55         .MatchAllWordForms = False
  56         
  57         .Forward = True
  58         .Wrap = wdFindContinue
  59         
  60         Do While .Execute
  61             With Selection
  62                 If InStr(1, .Text, vbCr) Then
  63                     ' Just process the chunk before any newline characters
  64                     ' We'll pick-up the rest with the next search
  65                     .Collapse
  66                     .MoveEndUntil vbCr
  67                 End If
  68                                        
  69                 ' Don't bother to markup newline characters (prevents a loop, as well)
  70                 If Not .Text = vbCr Then
  71                     .InsertBefore "= "
  72                     .InsertAfter " ="
  73                 Else
  74                     .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
  75                 End If
  76                 .Style = normalStyle
  77             End With
  78         Loop
  79     End With
  80 End Sub
  81 
  82 Private Sub ConvertH2()
  83     Dim normalStyle As Style
  84     Set normalStyle = ActiveDocument.Styles(wdStyleNormal)
  85     
  86     ActiveDocument.Select
  87     
  88     With Selection.Find
  89     
  90         .ClearFormatting
  91         .Style = ActiveDocument.Styles(wdStyleHeading2)
  92         .Text = ""
  93         
  94         .Format = True
  95         .MatchCase = False
  96         .MatchWholeWord = False
  97         .MatchWildcards = False
  98         .MatchSoundsLike = False
  99         .MatchAllWordForms = False
 100         
 101         .Forward = True
 102         .Wrap = wdFindContinue
 103         
 104         Do While .Execute
 105             With Selection
 106                 If InStr(1, .Text, vbCr) Then
 107                     ' Just process the chunk before any newline characters
 108                     ' We'll pick-up the rest with the next search
 109                     .Collapse
 110                     .MoveEndUntil vbCr
 111                 End If
 112                                        
 113                 ' Don't bother to markup newline characters (prevents a loop, as well)
 114                 If Not .Text = vbCr Then
 115                     .InsertBefore "== "
 116                     .InsertAfter " =="
 117                 Else
 118                     .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
 119                 End If
 120                 .Style = normalStyle
 121             End With
 122         Loop
 123     End With
 124 End Sub
 125 
 126 Private Sub ConvertH3()
 127     Dim normalStyle As Style
 128     Set normalStyle = ActiveDocument.Styles(wdStyleNormal)
 129     
 130     ActiveDocument.Select
 131     
 132     With Selection.Find
 133     
 134         .ClearFormatting
 135         .Style = ActiveDocument.Styles(wdStyleHeading3)
 136         .Text = ""
 137         
 138         .Format = True
 139         .MatchCase = False
 140         .MatchWholeWord = False
 141         .MatchWildcards = False
 142         .MatchSoundsLike = False
 143         .MatchAllWordForms = False
 144         
 145         .Forward = True
 146         .Wrap = wdFindContinue
 147         
 148         Do While .Execute
 149             With Selection
 150                 If InStr(1, .Text, vbCr) Then
 151                     ' Just process the chunk before any newline characters
 152                     ' We'll pick-up the rest with the next search
 153                     .Collapse
 154                     .MoveEndUntil vbCr
 155                 End If
 156                                        
 157                 ' Don't bother to markup newline characters (prevents a loop, as well)
 158                 If Not .Text = vbCr Then
 159                     .InsertBefore "=== "
 160                     .InsertAfter " ==="
 161                 Else
 162                     .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
 163                 End If
 164                 .Style = normalStyle
 165             End With
 166         Loop
 167     End With
 168 End Sub
 169 
 170 Private Sub ConvertBold()
 171     ActiveDocument.Select
 172     
 173     With Selection.Find
 174     
 175         .ClearFormatting
 176         .Font.Bold = True
 177         .Text = ""
 178         
 179         .Format = True
 180         .MatchCase = False
 181         .MatchWholeWord = False
 182         .MatchWildcards = False
 183         .MatchSoundsLike = False
 184         .MatchAllWordForms = False
 185         
 186         .Forward = True
 187         .Wrap = wdFindContinue
 188         
 189         Do While .Execute
 190             With Selection
 191                 If InStr(1, .Text, vbCr) Then
 192                     ' Just process the chunk before any newline characters
 193                     ' We'll pick-up the rest with the next search
 194                     .Collapse
 195                     .MoveEndUntil vbCr
 196                 End If
 197                                        
 198                 ' Don't bother to markup newline characters (prevents a loop, as well)
 199                 If Not .Text = vbCr Then
 200                     .InsertBefore "'''"
 201                     .InsertAfter "'''"
 202                 Else
 203                     .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
 204                 End If
 205                 
 206                 .Font.Bold = False
 207             End With
 208         Loop
 209     End With
 210 End Sub
 211 
 212 Private Sub ConvertItalic()
 213     ActiveDocument.Select
 214     
 215     With Selection.Find
 216     
 217         .ClearFormatting
 218         .Font.Italic = True
 219         .Text = ""
 220         
 221         .Format = True
 222         .MatchCase = False
 223         .MatchWholeWord = False
 224         .MatchWildcards = False
 225         .MatchSoundsLike = False
 226         .MatchAllWordForms = False
 227         
 228         .Forward = True
 229         .Wrap = wdFindContinue
 230         
 231         Do While .Execute
 232             Selection.Font.Italic = False
 233             With Selection
 234                 If InStr(1, .Text, vbCr) Then
 235                     ' Just process the chunk before any newline characters
 236                     ' We'll pick-up the rest with the next search
 237                     .Collapse
 238                     .MoveEndUntil vbCr
 239                 End If
 240                                        
 241                 ' Don't bother to markup newline characters (prevents a loop, as well)
 242                 If Not .Text = vbCr Then
 243                     .InsertBefore "''"
 244                     .InsertAfter "''"
 245                 Else
 246                     .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
 247                 End If
 248             End With
 249         Loop
 250     End With
 251 End Sub
 252 
 253 Private Sub ConvertUnderline()
 254     ActiveDocument.Select
 255     
 256     With Selection.Find
 257     
 258         .ClearFormatting
 259         .Font.Underline = True
 260         .Text = ""
 261         
 262         .Format = True
 263         .MatchCase = False
 264         .MatchWholeWord = False
 265         .MatchWildcards = False
 266         .MatchSoundsLike = False
 267         .MatchAllWordForms = False
 268         
 269         .Forward = True
 270         .Wrap = wdFindContinue
 271         
 272         Do While .Execute
 273             With Selection
 274                 If InStr(1, .Text, vbCr) Then
 275                     ' Just process the chunk before any newline characters
 276                     ' We'll pick-up the rest with the next search
 277                     .Collapse
 278                     .MoveEndUntil vbCr
 279                 End If
 280                                        
 281                 ' Don't bother to markup newline characters (prevents a loop, as well)
 282                 If Not .Text = vbCr Then
 283                     .InsertBefore "__"
 284                     .InsertAfter "__"
 285                 Else
 286                     .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
 287                 End If
 288                 .Font.Underline = False
 289             End With
 290         Loop
 291     End With
 292 End Sub
 293 
 294 Private Sub ConvertLists()
 295     Dim para As Paragraph
 296     For Each para In ActiveDocument.ListParagraphs
 297         With para.Range
 298             If .ListFormat.ListType = wdListBullet Then
 299                 .InsertBefore String(.ListFormat.ListLevelNumber, " ") + "* "
 300             Else
 301                 .InsertBefore String(.ListFormat.ListLevelNumber, " ") + "1. "
 302             End If
 303             
 304             .ListFormat.RemoveNumbers
 305         End With
 306     Next para
 307 End Sub
 308 
 309 Private Sub ConvertTables()
 310     Dim thisTable As Table
 311     Dim thisRow As Row
 312     Dim ElRango As Object
 313     For Each thisTable In ActiveDocument.Tables
 314         With thisTable
 315             For Each thisRow In .Rows
 316                 thisRow.Range.InsertBefore "||"
 317                 If thisRow.Index = .Rows.Count Then
 318                     'Cerramos la tabla al final
 319                     thisRow.Range.InsertAfter "||"
 320                 End If
 321             Next thisRow
 322             Set ElRango = .ConvertToText(Separator:="||")
 323             With ElRango.Find
 324                 .ClearFormatting
 325                 .Text = "^p"
 326                 With .Replacement
 327                     .ClearFormatting
 328                     .Text = ""
 329                 End With
 330                 .Execute Replace:=wdReplaceAll
 331             End With
 332         End With
 333     Next thisTable
 334 End Sub
 335 
 336 
 337 Private Sub EscapeSpecialChar()
 338 
 339     ActiveDocument.Select
 340     
 341     With Selection.Find
 342         .ClearFormatting
 343         .Text = "%"
 344         With .Replacement
 345             .ClearFormatting
 346             .Text = "~np~%~/np~"
 347         End With
 348         .Execute Replace:=wdReplaceAll
 349     End With
 350 
 351 End Sub
 352 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux