Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for wpsaveas.vbs

(view source code of wpsaveas.vbs as plain text)

  1. ' This script opens a WordPerfect
  2. ' document, and saves it as HTML file.
  3. '
  4. ' Tested with Corel WordPerfect 12 only.
  5. '
  6. ' Written by Rob van der Woude
  7. ' http://www.robvanderwoude.com
  8.  
  9. Option Explicit
  10.  
  11. WP2HTML "D:\MyFiles\MyDoc.wpd"
  12.  
  13. Sub WP2HTML( myFile )
  14. ' This subroutine opens a WordPerfect document,
  15. ' then saves it as HTML, and closes WordPerfect.
  16. ' If the HTML file exists, the subroutine will
  17. ' prompt for overwrite.
  18. ' If WordPerfect was already active, the subroutine
  19. ' will prompt the user to save the changes in other
  20. ' documents.
  21. '
  22. ' Written by Rob van der Woude
  23. ' http://www.robvanderwoude.com
  24.  
  25. 	' Standard housekeeping
  26. 	Dim objFSO, objWP, objWPFile, strHTMLFile, strWPFile
  27.  
  28. 	Const AmiPro_12_FileOpen_Format                              = 201
  29. 	Const AmiPro_12A_FileOpen_Format                             = 202
  30. 	Const AmiPro_12B_FileOpen_Format                             = 203
  31. 	Const AmiPro_20_FileOpen_Format                              = 204
  32. 	Const AmiPro_30_FileOpen_Format                              = 205
  33. 	Const ANSIDelimitedTextWindows_FileOpen_Format               = 406
  34. 	Const ANSIGenericWordProcessor_Windows_FileOpen_Format       = 407
  35. 	Const ANSIText_Windows_FileOpen_Format                       = 161
  36. 	Const AreAHangol_FileOpen_Format                             = 375
  37. 	Const Aruga_23_FileOpen_Format                               = 396
  38. 	Const ASCIIStandard_FileOpen_Format                          = 160
  39. 	Const ASCIIStripped_FileOpen_Format                          = 165
  40. 	Const DelimitedText_FileOpen_Format                          = 163
  41. 	Const DisplayWrite_40_FileOpen_Format                        =  82
  42. 	Const DisplayWrite_42_FileOpen_Format                        =  83
  43. 	Const DisplayWrite_50_FileOpen_Format                        =  84
  44. 	Const Excel_40_FileOpen_Format                               = 807
  45. 	Const FFT_FileOpen_Format                                    =  81
  46. 	Const Hana_FileOpen_Format                                   = 376
  47. 	Const HTML_FileOpen_Format                                   = 226
  48. 	Const Ichitaro_3x_FileOpen_Format                            = 392
  49. 	Const Ichitaro_4x_FileOpen_Format                            = 393
  50. 	Const Ichitaro_5x_FileOpen_Format                            = 394
  51. 	Const Kermit_7bit_Transfer_FileOpen_Format                   = 173
  52. 	Const Matu_4_FileOpen_Format                                 = 397
  53. 	Const Matu_5_FileOpen_Format                                 = 398
  54. 	Const Matu_6_FileOpen_Format                                 = 399
  55. 	Const MicroSoftWord_40_FileOpen_Format                       =  52
  56. 	Const MicroSoftWord_50_FileOpen_Format                       =  53
  57. 	Const MicroSoftWord_55_FileOpen_Format                       =  54
  58. 	Const MultiMate_33_FileOpen_Format                           = 100
  59. 	Const MultiMate_40_FileOpen_Format                           = 103
  60. 	Const MultiMateAdvantage_36_FileOpen_Format                  = 101
  61. 	Const MultiMateAdvantageII_10_FileOpen_Format                = 102
  62. 	Const NavyDIF_FileOpen_Format                                = 175
  63. 	Const OfficeWriter_60_FileOpen_Format                        = 120
  64. 	Const OfficeWriter_611_FileOpen_Format                       = 122
  65. 	Const OfficeWriter_61_FileOpen_Format                        = 121
  66. 	Const OfficeWriter_62_FileOpen_Format                        = 123
  67. 	Const P1EXE_FileOpen_Format                                  = 395
  68. 	Const RFT_FileOpen_Format                                    =  80
  69. 	Const RTF_FileOpen_Format                                    = 150
  70. 	Const RTFJ_FileOpen_Format                                   = 391
  71. 	Const SGML_FileOpen_Format                                   = 227
  72. 	Const WaiSing_251_FileOpen_Format                            = 380
  73. 	Const WindowsWrite_FileOpen_Format                           = 210
  74. 	Const WordForWindows_10_FileOpen_Format                      =  60
  75. 	Const WordForWindows_11_FileOpen_Format                      =  61
  76. 	Const WordForWindows_12_FileOpen_Format                      = 371
  77. 	Const WordForWindows_1A_FileOpen_Format                      =  62
  78. 	Const WordForWindows_20_FileOpen_Format                      =  63
  79. 	Const WordForWindows_20a_FileOpen_Format                     =  64
  80. 	Const WordForWindows_20b_FileOpen_Format                     =  65
  81. 	Const WordForWindows_20c_FileOpen_Format                     =  66
  82. 	Const WordForWindows_50_FileOpen_Format                      = 372
  83. 	Const WordForWindows_60_FileOpen_Format                      =  67
  84. 	Const WordPerfect_42_FileOpen_Format                         =   1
  85. 	Const WordPerfect_50_FileOpen_Format                         =   2
  86. 	Const WordPerfect_51_FileOpen_Format                         =   3
  87. 	Const WordPerfect_5xA_FileOpen_Format                        = 370
  88. 	Const WordPerfect_60_FileOpen_Format                         =   4
  89. 	Const WordPerfect_6_7_8_FileOpen_Format                      =   4
  90. 	Const WordPerfect_7_FileOpen_Format                          =   6
  91. 	Const WordPerfect_90_FileOpen_Format                         =   4
  92. 	Const WordPerfect_CompoundFile_FileOpen_Format               =   6
  93. 	Const WordStar2000_10_FileOpen_Format                        =  40
  94. 	Const WordStar2000_20_FileOpen_Format                        =  41
  95. 	Const WordStar2000_30_FileOpen_Format                        =  42
  96. 	Const WordStar_331_FileOpen_Format                           =  31
  97. 	Const WordStar_33_FileOpen_Format                            =  30
  98. 	Const WordStar_34_FileOpen_Format                            =  32
  99. 	Const WordStar_40_FileOpen_Format                            =  33
  100. 	Const WordStar_50_FileOpen_Format                            =  34
  101. 	Const WordStar_55_FileOpen_Format                            =  35
  102. 	Const WordStar_60_FileOpen_Format                            =  36
  103. 	Const WPS_Chinese_FileOpen_Format                            = 377
  104. 	Const XML_UTF16Big_FileOpen_Format                           = 222
  105. 	Const XML_UTF16Lit_FileOpen_Format                           = 223
  106. 	Const XML_UTF8_FileOpen_Format                               = 224
  107. 	Const XyWriteIIIPlus_355_FileOpen_Format                     = 190
  108. 	Const XyWriteIIIPlus_356_FileOpen_Format                     = 191
  109.  
  110. 	Const AmiPro_12_FileSave_ExportType                          = 201
  111. 	Const AmiPro_12A_FileSave_ExportType                         = 202
  112. 	Const AmiPro_12B_FileSave_ExportType                         = 203
  113. 	Const AmiPro_20_FileSave_ExportType                          = 204
  114. 	Const AmiPro_30_FileSave_ExportType                          = 205
  115. 	Const ANSIDelimitedTextWindows_FileSave_ExportType           = 406
  116. 	Const ANSIGeneratedWordProcessor_Windows_FileSave_ExportType = 407
  117. 	Const ANSIText_Windows_FileSave_ExportType                   = 161
  118. 	Const AreAHangol_FileSave_ExportType                         = 375
  119. 	Const Aruga_23_FileSave_ExportType                           = 396
  120. 	Const ASCIIStandard_FileSave_ExportType                      = 160
  121. 	Const ASCIIStripped_FileSave_ExportType                      = 165
  122. 	Const DelimitedText_FileSave_ExportType                      = 163
  123. 	Const DisplayWrite_40_FileSave_ExportType                    =  82
  124. 	Const DisplayWrite_42_FileSave_ExportType                    =  83
  125. 	Const DisplayWrite_50_FileSave_ExportType                    =  84
  126. 	Const EDGAR_FileSave_ExportType                              = 225
  127. 	Const Excel_40_FileSave_ExportType                           = 807
  128. 	Const FFT_FileSave_ExportType                                =  81
  129. 	Const Hana_FileSave_ExportType                               = 376
  130. 	Const HTML_FileSave_ExportType                               = 226
  131. 	Const Ichitaro_3x_FileSave_ExportType                        = 392
  132. 	Const Ichitaro_4x_FileSave_ExportType                        = 393
  133. 	Const Ichitaro_5x_FileSave_ExportType                        = 394
  134. 	Const Kermit_7bit_Transfer_FileSave_ExportType               = 173
  135. 	Const Matu_4_FileSave_ExportType                             = 397
  136. 	Const Matu_5_FileSave_ExportType                             = 398
  137. 	Const Matu_6_FileSave_ExportType                             = 399
  138. 	Const MicroSoftWord_40_FileSave_ExportType                   =  52
  139. 	Const MicroSoftWord_50_FileSave_ExportType                   =  53
  140. 	Const MicroSoftWord_55_FileSave_ExportType                   =  54
  141. 	Const MultiMate_33_FileSave_ExportType                       = 100
  142. 	Const MultiMate_40_FileSave_ExportType                       = 103
  143. 	Const MultiMateAdvantage_36_FileSave_ExportType              = 101
  144. 	Const MultiMateAdvantageII_10_FileSave_ExportType            = 102
  145. 	Const NavyDIF_FileSave_ExportType                            = 175
  146. 	Const OfficeWriter_60_FileSave_ExportType                    = 120
  147. 	Const OfficeWriter_611_FileSave_ExportType                   = 122
  148. 	Const OfficeWriter_61_FileSave_ExportType                    = 121
  149. 	Const OfficeWriter_62_FileSave_ExportType                    = 123
  150. 	Const P1EXE_FileSave_ExportType                              = 395
  151. 	Const QuattroPro_30_FileSave_ExportType                      = 836
  152. 	Const QuattroPro_40_FileSave_ExportType                      = 837
  153. 	Const RFT_FileSave_ExportType                                =  80
  154. 	Const RTF_FileSave_ExportType                                = 150
  155. 	Const RTFJ_FileSave_ExportType                               = 391
  156. 	Const SGML_FileSave_ExportType                               = 227
  157. 	Const WaiSing_251_FileSave_ExportType                        = 380
  158. 	Const WindowsWrite_FileSave_ExportType                       = 210
  159. 	Const WordForWindows_10_FileSave_ExportType                  =  60
  160. 	Const WordForWindows_11_FileSave_ExportType                  =  61
  161. 	Const WordForWindows_12_FileSave_ExportType                  = 371
  162. 	Const WordForWindows_1A_FileSave_ExportType                  =  62
  163. 	Const WordForWindows_20_FileSave_ExportType                  =  63
  164. 	Const WordForWindows_20a_FileSave_ExportType                 =  64
  165. 	Const WordForWindows_20b_FileSave_ExportType                 =  65
  166. 	Const WordForWindows_20c_FileSave_ExportType                 =  66
  167. 	Const WordForWindows_50_FileSave_ExportType                  = 372
  168. 	Const WordForWindows_60_FileSave_ExportType                  =  67
  169. 	Const WordPerfect_42_FileSave_ExportType                     =   1
  170. 	Const WordPerfect_50_FileSave_ExportType                     =   2
  171. 	Const WordPerfect_51_FileSave_ExportType                     =   3
  172. 	Const WordPerfect_5xA_FileSave_ExportType                    = 370
  173. 	Const WordPerfect_60_FileSave_ExportType                     =   4
  174. 	Const WordPerfect_6_7_8_FileSave_ExportType                  =   4
  175. 	Const WordPerfect_7_FileSave_ExportType                      =   6
  176. 	Const WordPerfect_90_FileSave_ExportType                     =   4
  177. 	Const WordPerfect_CompoundFile_FileSave_ExportType           =   6
  178. 	Const WordStar2000_10_FileSave_ExportType                    =  40
  179. 	Const WordStar2000_20_FileSave_ExportType                    =  41
  180. 	Const WordStar2000_30_FileSave_ExportType                    =  42
  181. 	Const WordStar_331_FileSave_ExportType                       =  31
  182. 	Const WordStar_33_FileSave_ExportType                        =  30
  183. 	Const WordStar_34_FileSave_ExportType                        =  32
  184. 	Const WordStar_40_FileSave_ExportType                        =  33
  185. 	Const WordStar_50_FileSave_ExportType                        =  34
  186. 	Const WordStar_55_FileSave_ExportType                        =  35
  187. 	Const WordStar_60_FileSave_ExportType                        =  36
  188. 	Const WPS_Chinese_FileSave_ExportType                        = 377
  189. 	Const XML_UTF16Big_FileSave_ExportType                       = 222
  190. 	Const XML_UTF16Lit_FileSave_ExportType                       = 223
  191. 	Const XML_UTF8_FileSave_ExportType                           = 224
  192. 	Const XyWriteIIIPlus_355_FileSave_ExportType                 = 190
  193. 	Const XyWriteIIIPlus_356_FileSave_ExportType                 = 191
  194.  
  195. 	Const No_FileSave_Overwrite                                  =   0
  196. 	Const Prompt_FileSave_Overwrite                              =   2
  197. 	Const Yes_FileSave_Overwrite                                 =   1
  198.  
  199. 	Const vbBinaryCompare                                        =   0
  200. 	Const vbTextCompare                                          =   1
  201.  
  202. 	' Create a File System object
  203. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  204.  
  205. 	' Create a WordPerfect OLE Automation object
  206. 	Set objWP = CreateObject( "WordPerfect.PerfectScript" )
  207.  
  208. 	With objWP
  209. 		' Check if the WordPerfect file exists
  210. 		If objFSO.FileExists( myFile ) Then
  211. 			Set objWPFile   = objFSO.GetFile( myFile )
  212. 		Else
  213. 			WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
  214. 			' Close WordPerfect
  215. 			.ExitWordPerfect
  216. 			Exit Sub
  217. 		End If
  218. 		strWPFile = objWPFile.Path
  219. 		strHTMLFile = objFSO.BuildPath( objWPFile.ParentFolder, Left( objWPFile.Name, Len( objWPFile.Name ) - 3 ) & "html" )
  220.  
  221. 		' Maximize the window
  222. 		.AppMaximize
  223.  
  224. 		' Open the document
  225. 		On Error Resume Next
  226. 		.FileOpen strWPFile, WordPerfect_6_7_8_FileOpen_Format
  227. 		If Err Then
  228. 			WScript.Echo "FILE OPEN ERROR: " & Err.Number & vbCrLf & Err.Description & vbCrLf
  229. 			Err.Clear
  230. 			' Close WordPerfect
  231. 			.ExitWordPerfect
  232. 			Exit Sub
  233. 		End If
  234.  
  235. 		' Save the document as HTML file
  236. 		.FileSave strHTMLFile, HTML_FileSave_ExportType, Prompt_FileSave_Overwrite
  237. 		If Err Then
  238. 			WScript.Echo "FILE SAVE AS ERROR: " & Err.Number & vbCrLf & Err.Description & vbCrLf
  239. 			Err.Clear
  240. 		End If
  241.  
  242. 		' Close WordPerfect
  243. 		.ExitWordPerfect
  244. 		If Err Then
  245. 			WScript.Echo "PROGRAM CLOSE ERROR: " & Err.Number & vbCrLf & Err.Description & vbCrLf
  246. 			Err.Clear
  247. 		End If
  248. 		On Error Goto 0
  249. 	End With
  250.  
  251. 	' Release the object
  252. 	Set objWP = Nothing
  253. End Sub
  254.  

page last modified: 2024-04-16; loaded in 0.0126 seconds