- They are already familiar with Word and its formatting features.
- Word comes installed on their computer and they do not want to purchase additional HTML authoring software.
- They have numerous files in Word format that they want on a website in HTML. Simply exporting them to HTML is the fastest way.
Save AS HTML from wordwith the extension .htmand exporting via code using vbscript Option Explicit |
| 2 | |
| 3 | 'declare all variables |
| 4 | Dim objWord |
| 5 | Dim oDoc |
| 6 | Dim objFso |
| 7 | Dim colFiles |
| 8 | Dim curFile |
| 9 | Dim curFileName |
| 10 | Dim folderToScanExists |
| 11 | Dim folderToSaveExists |
| 12 | Dim objFolderToScan |
| 13 | |
| 14 | 'set some of the variables |
| 15 | folderToScanExists False |
| 16 | folderToSaveExists False |
| 17 | Const wdSaveFormat 10 'for Filtered HTML output |
| 18 | |
| 19 | '******************************************** |
| 20 | 'change the following to fit your system |
| 21 | Const folderToScan C:\Word\documentation\ |
| 22 | Const folderToSave C:\Inetpub\wwwroot\word\ |
| 23 | '******************************************** |
| 24 | |
| 25 | 'Use FSO to see if the folders to read from |
| 26 | 'and write to both exist. |
| 27 | 'If they do then set both flags to TRUE |
| 28 | 'and proceed with the function |
| 29 | Set objFso CreateObject( Scripting.FileSystemObject ) |
| 30 | If objFso.FolderExists(folderToScan) Then |
| 31 | folderToScanExists True |
| 32 | Else |
| 33 | MsgBox Folder to scan from does not exist! 48 File System Error |
| 34 | End If |
| 35 | If objFso.FolderExists(folderToSave) Then |
| 36 | folderToSaveExists True |
| 37 | Else |
| 38 | MsgBox Folder to copy to does not exist! 48 File System Error |
| 39 | End If |
| 40 | |
| 41 | If (folderToScanExists And folderToSaveExists) Then |
| 42 | 'get your folder to scan |
| 43 | Set objFolderToScan objFso.GetFolder(folderToScan) |
| 44 | 'put al the files under it in a collection |
| 45 | Set colFiles objFolderToScan.Files |
| 46 | 'create an instance of Word |
| 47 | Set objWord CreateObject( Word.Application ) |
| 48 | If objWord Is Nothing Then |
| 49 | MsgBox Couldn't start Word. 48 Application Start Error |
| 50 | Else |
| 51 | 'for each file |
| 52 | For Each curFile in colFiles |
| 53 | 'only if the file is of type DOC |
| 54 | If (objFso.GetExtensionName(curFile) doc ) Then |
| 55 | 'get the filename without extension |
| 56 | curFileName curFile.Name |
| 57 | curFileName Mid(curFileName 1 InStrRev(curFileName . ) - 1) |
| 58 | 'open the file inside Word |
| 59 | objWord.Documents.Open objFso.GetAbsolutePathName(curFile) |
| 60 | 'do all this in the background |
| 61 | objWord.Visible False |
| 62 | 'create a new document and save it as Filtered HTML |
| 63 | Set oDoc objWord.ActiveDocument |
| 64 | oDoc.SaveAs folderToSave & curFileName & .htm wdSaveFormat |
| 65 | oDoc.Close |
| 66 | Set oDoc Nothing |
| 67 | End If |
| 68 | Next |
| 69 | End If |
| 70 | 'close Word |
| 71 | objWord.Quit |
| 72 | 'set all objects and collections to nothing |
| 73 | Set objWord Nothing |
| 74 | Set colFiles Nothing |
| 75 | Set objFolderToScan Nothing |
| 76 | End If |
| 77 | |
| 78 | Set objFso Nothing |