Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for wsaveas.vbs

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

  1. Option Explicit
  2.  
  3. Doc2HTML "C:\Documents and Settings\MyUserID\My Documents\resume.doc"
  4.  
  5.  
  6. Sub Doc2HTML( myFile )
  7. ' This subroutine opens a Word document,
  8. ' then saves it as HTML, and closes Word.
  9. ' If the HTML file exists, it is overwritten.
  10. ' If Word was already active, the subroutine
  11. ' will leave the other document(s) alone and
  12. ' close only its "own" document.
  13. '
  14. ' Written by Rob van der Woude
  15. ' http://www.robvanderwoude.com
  16.  
  17. 	' Standard housekeeping
  18. 	Dim objDoc, objFile, objFSO, objWord, strFile, strHTML
  19.  
  20. 	Const wdFormatDocument                    =  0
  21. 	Const wdFormatDocument97                  =  0
  22. 	Const wdFormatDocumentDefault             = 16
  23. 	Const wdFormatDOSText                     =  4
  24. 	Const wdFormatDOSTextLineBreaks           =  5
  25. 	Const wdFormatEncodedText                 =  7
  26. 	Const wdFormatFilteredHTML                = 10
  27. 	Const wdFormatFlatXML                     = 19
  28. 	Const wdFormatFlatXMLMacroEnabled         = 20
  29. 	Const wdFormatFlatXMLTemplate             = 21
  30. 	Const wdFormatFlatXMLTemplateMacroEnabled = 22
  31. 	Const wdFormatHTML                        =  8
  32. 	Const wdFormatPDF                         = 17
  33. 	Const wdFormatRTF                         =  6
  34. 	Const wdFormatTemplate                    =  1
  35. 	Const wdFormatTemplate97                  =  1
  36. 	Const wdFormatText                        =  2
  37. 	Const wdFormatTextLineBreaks              =  3
  38. 	Const wdFormatUnicodeText                 =  7
  39. 	Const wdFormatWebArchive                  =  9
  40. 	Const wdFormatXML                         = 11
  41. 	Const wdFormatXMLDocument                 = 12
  42. 	Const wdFormatXMLDocumentMacroEnabled     = 13
  43. 	Const wdFormatXMLTemplate                 = 14
  44. 	Const wdFormatXMLTemplateMacroEnabled     = 15
  45. 	Const wdFormatXPS                         = 18
  46. 	Const wdFormatOfficeDocumentTemplate      = 23 ' Found by Scott Ness
  47. 	Const wdFormatMediaWiki                   = 24 ' Found by Scott Ness; requires Microsoft Office Word Add-in For MediaWiki (http://www.microsoft.com/download/en/details.aspx?id=12298)
  48.  
  49. 	' Create a File System object
  50. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  51.  
  52. 	' Create a Word object
  53. 	Set objWord = CreateObject( "Word.Application" )
  54.  
  55. 	With objWord
  56. 		' True: make Word visible; False: invisible
  57. 		.Visible = True
  58.  
  59. 		' Check if the Word document exists
  60. 		If objFSO.FileExists( myFile ) Then
  61. 			Set objFile = objFSO.GetFile( myFile )
  62. 			strFile = objFile.Path
  63. 		Else
  64. 			WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
  65. 			' Close Word
  66. 			.Quit
  67. 			Exit Sub
  68. 		End If
  69.  
  70. 		' Build the fully qualified HTML file name
  71. 		strHTML = objFSO.BuildPath( objFile.ParentFolder, _
  72. 		          objFSO.GetBaseName( objFile ) & ".html" )
  73.  
  74. 		' Open the Word document
  75. 		.Documents.Open strFile
  76.  
  77. 		' Make the opened file the active document
  78. 		Set objDoc = .ActiveDocument
  79.  
  80. 		' Save as HTML
  81. 		objDoc.SaveAs strHTML, wdFormatFilteredHTML
  82.  
  83. 		' Close the active document
  84. 		objDoc.Close
  85.  
  86. 		' Close Word
  87. 		.Quit
  88. 	End With
  89. End Sub
  90.  

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