Advertisement
Popicaru

Macrouv1

May 26th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.49 KB | None | 0 0
  1. Sub Macrou()
  2.  
  3.  
  4. Dim ReadData As String
  5. Dim line As String
  6. Dim aString As String
  7. Dim bString As String
  8. Dim sizeString As String
  9. Dim hyperString As String
  10. Dim linkString As String
  11. Dim faceString As String
  12. Dim faceTypeString As String
  13. Dim pos1 As Integer
  14. Dim pos2 As Integer
  15. Dim pos3 As Integer
  16. Dim pos4 As Integer
  17. Dim i As Integer
  18. Dim j As Integer
  19. Dim tablesAdded As Boolean
  20. Dim colorString As String
  21. Open "E:\office.html" For Input As #1
  22. Do Until EOF(1)
  23. Line Input #1, ReadData
  24. pos1 = InStr(ReadData, "<")
  25. pos2 = InStr(ReadData, ">")
  26. pos3 = InStr(ReadData, "</")
  27.  
  28. aString = Mid(ReadData, (pos1 + 1), (pos2 - pos1 - 1))
  29. pos4 = Len(aString)
  30. 'Selection.TypeText (ReadData)
  31. Selection.Font.Size = 12
  32. Selection.Font.Name = "Times New Roman"
  33. Selection.Font.Bold = False
  34. Selection.Font.Italic = False
  35. Selection.Font.ColorIndex = wdBlack
  36. If StrComp(aString, "b") = 0 Then
  37. Selection.Font.Bold = True
  38. Selection.Font.ColorIndex = wdBlack
  39. bString = Mid(ReadData, (pos1 + 3), (pos3 - pos1 - 3))
  40. Selection.TypeText (bString)
  41. Selection.TypeParagraph
  42. End If
  43.  
  44. If StrComp(aString, "i") = 0 Then
  45. Selection.Font.Bold = False
  46. Selection.Font.Italic = True
  47. Selection.Font.ColorIndex = wdBlack
  48. bString = Mid(ReadData, (pos1 + 3), (pos3 - pos1 - 3))
  49. Selection.TypeText (bString)
  50. Selection.TypeParagraph
  51. End If
  52.  
  53. If StrComp(Left(aString, 4), "font") = 0 Then
  54. colorString = Mid(aString, (pos1 + 13), (pos4 - pos1 - 13))
  55. sizeString = Mid(aString, (pos1 + 12), (pos4 - pos1 - 12))
  56. faceString = Mid(aString, (pos1 + 5), (pos1 + 3))
  57. faceTypeString = Mid(aString, (pos1 + 11), (pos4 - pos1 - 11))
  58.  
  59.  
  60. If StrComp(colorString, "red") = 0 Then
  61. Selection.Font.ColorIndex = wdRed
  62. Selection.TypeText (Mid(ReadData, (pos4 + 3), (pos3 - pos4 - 3)))
  63. Selection.TypeParagraph
  64. End If
  65. If StrComp(colorString, "yellow") = 0 Then
  66. Selection.Font.ColorIndex = wdYellow
  67. Selection.TypeText (Mid(ReadData, (pos4 + 3), (pos3 - pos4 - 3)))
  68. Selection.TypeParagraph
  69. End If
  70. If StrComp(colorString, "blue") = 0 Then
  71. Selection.Font.ColorIndex = wdBlue
  72. Selection.TypeText (Mid(ReadData, (pos4 + 3), (pos3 - pos4 - 3)))
  73. Selection.TypeParagraph
  74. End If
  75.  
  76. If IsNumeric(sizeString) Then
  77.  
  78. Selection.Font.Size = sizeString
  79. Selection.TypeText (Mid(ReadData, (pos4 + 3), (pos3 - pos4 - 3)))
  80. Selection.TypeParagraph
  81.  
  82. End If
  83.  
  84. If StrComp(faceString, "face") = 0 Then
  85.  
  86. Selection.Font.Name = faceTypeString
  87. Selection.TypeText (Mid(ReadData, (pos4 + 3), (pos3 - pos4 - 3)))
  88. Selection.TypeParagraph
  89.  
  90. End If
  91.  
  92.  
  93.  
  94.  
  95.  
  96. Selection.ClearFormatting
  97. End If
  98.  
  99. If StrComp(aString, "ul") = 0 Then
  100. Selection.Font.Bold = False
  101. Selection.Font.Italic = False
  102.  
  103. Dim listItem As String
  104. Selection.Range.ListFormat.ApplyBulletDefault
  105.  
  106. Do Until InStr(line, "</ul>") > 0
  107. Line Input #1, line
  108. If StrComp(line, "</ul>") <> 0 Then
  109. pos1 = InStr(line, "<")
  110. pos2 = InStr(line, "</")
  111.  
  112. listItem = Mid(line, (pos1 + 4), (pos2 - pos1 - 4))
  113. 'MsgBox listItem
  114. Selection.TypeText (listItem)
  115. Selection.TypeParagraph
  116.  
  117. End If
  118. Loop
  119. 'Selection.Range.ParagraphFormat.Reset
  120. Selection.ClearFormatting
  121. 'MsgBox aString
  122. 'Selection.TypeText (bString)
  123. Selection.TypeParagraph
  124. End If
  125.  
  126. If StrComp(aString, "ol") = 0 Then
  127. Selection.Font.Bold = False
  128. Selection.Font.Italic = False
  129.  
  130. Selection.Range.ListFormat.ApplyNumberDefault
  131.  
  132. Do Until InStr(line, "</ol>") > 0
  133. Line Input #1, line
  134. If StrComp(line, "</ol>") <> 0 Then
  135. pos1 = InStr(line, "<")
  136. pos2 = InStr(line, "</")
  137.  
  138. listItem = Mid(line, (pos1 + 4), (pos2 - pos1 - 4))
  139. 'MsgBox listItem
  140. Selection.TypeText (listItem)
  141. Selection.TypeParagraph
  142.  
  143. End If
  144. Loop
  145. Selection.ClearFormatting
  146. 'MsgBox aString
  147. 'Selection.TypeText (bString)
  148. Selection.TypeParagraph
  149. End If
  150.  
  151. If StrComp(aString, "table") = 0 Then
  152. Selection.Font.Bold = False
  153. Selection.Font.Italic = False
  154. Dim trString As String
  155. Dim tdItem As String
  156. Dim line2 As String
  157. Dim pos5 As Integer
  158. Dim pos6 As Integer
  159. Dim nrRows As Integer
  160. Dim nrCols As Integer
  161. nrRows = 0
  162. nrCols = 0
  163.  
  164.  
  165. line = "<table>"
  166. Do Until InStr(line, "</table>") > 0
  167. Line Input #1, line
  168. If StrComp(line, "</table>") <> 0 Then
  169. pos5 = InStr(line, "<")
  170. pos6 = InStr(line, ">")
  171.  
  172. trString = Mid(line, (pos5 + 1), (pos6 - pos5 - 1))
  173. 'MsgBox trString
  174. If StrComp(trString, "tr") = 0 Then
  175. nrRows = nrRows + 1
  176. nrCols = 0
  177. line2 = ""
  178. Do Until (InStr(line2, "</tr>") > 0)
  179. Line Input #1, line2
  180. If ((StrComp(line2, "</tr>") <> 0) And (InStr(line2, "</tr>") <= 0)) Then
  181. pos1 = InStr(line2, "<")
  182. pos2 = InStr(line2, "</")
  183. nrCols = nrCols + 1
  184. tdItem = Mid(line2, (pos1 + 4), (pos2 - pos1 - 4))
  185.  
  186.  
  187.  
  188. End If
  189. Loop
  190. End If
  191. End If
  192. Loop
  193.  
  194.  
  195. End If
  196.  
  197.  
  198.  
  199. If StrComp(Left(aString, 6), "a href") = 0 Then
  200.  
  201. hyperString = Mid(aString, (pos1 + 8), (pos4 - pos1 - 8))
  202. linkString = Mid(ReadData, (pos4 + 3), (pos3 - pos4 - 3))
  203. Selection.Hyperlinks.Add Anchor:=Selection.Range, _
  204. Address:=hyperString, TextToDisplay:=linkString
  205.  
  206.  
  207. End If
  208.  
  209.  
  210.  
  211. Loop
  212.  
  213. Close #1
  214.  
  215. Open "E:\office.html" For Input As #2
  216. If StrComp(aString, "table") = 0 Then
  217. Selection.Font.Bold = False
  218. Selection.Font.Italic = False
  219.  
  220.  
  221.  
  222.  
  223. Dim tblNew As Table
  224. Set tblNew = Selection.Tables.Add(Selection.Range, nrRows, nrCols)
  225. nrRows = 0
  226. nrCols = 0
  227. line = "<table>"
  228. Do Until InStr(line, "</table>") > 0
  229. Line Input #2, line
  230. If StrComp(line, "</table>") <> 0 Then
  231. pos5 = InStr(line, "<")
  232. pos6 = InStr(line, ">")
  233.  
  234. trString = Mid(line, (pos5 + 1), (pos6 - pos5 - 1))
  235. 'MsgBox trString
  236. If StrComp(trString, "tr") = 0 Then
  237. nrRows = nrRows + 1
  238. nrCols = 0
  239. line2 = ""
  240. Do Until (InStr(line2, "</tr>") > 0)
  241. Line Input #2, line2
  242. If ((StrComp(line2, "</tr>") <> 0) And (InStr(line2, "</tr>") <= 0)) Then
  243. pos1 = InStr(line2, "<")
  244. pos2 = InStr(line2, "</")
  245. nrCols = nrCols + 1
  246. tdItem = Mid(line2, (pos1 + 4), (pos2 - pos1 - 4))
  247.  
  248. Selection.Tables.Item(1).Cell(nrRows, nrCols).Range.Text = tdItem
  249.  
  250. End If
  251. Loop
  252. End If
  253. End If
  254. Loop
  255.  
  256.  
  257. End If
  258.  
  259. Close #2
  260.  
  261.  
  262. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement