Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for wpd2doc.vbs

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

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

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