Tour : How to convert all Word Document of any folder into HTML
Step 1. Open VBScript Editor
Step 2. Program Code
Step 3. Required Variable Declaration
Step 4. Word Application Object creation
Step 5. Constant variable Declaration
Step 6. Create Scripting FileSystemObject
Step 7. Get the AbsolutePathName()
Step 8. Check and Create HTML Folder
Step 9. Get all Files of specified path
Step 10. Iterate all files using "For Each loop"
Step 11. Check the File Extension
Step 12. Get FileName
Step 13. Open the word file into Word Application
Step 14. Save Document into HTML format
Step 15. Close the open document
Step 16. Quit the Word Application Object
Step 17. Save and Run Script file
Step 18. Opened Word Application
Step 19. Congratulation ! :)
Step 20. Visit GoLearningBus.Com for more "www.vbsedit.com" training
1. Open VBScript Editor
Open the VB Script editor either from desktop VBS shortcut or from start menu.
2. Program Code
Here you see the Program for "How to Convert the Word Document into Html files in Windows using VBS".
In next slides we will discuss whole code line by line for better understanding.
3. Required Variable Declaration
Here we Declare the Required variables.
We use this variable as global variable and use when we declare required object.
4. Word Application Object creation
We create the Word Application object here because we want convert the Word document into html, so for this we need this object to open document file.we set the visible property true because we want to see the document file which will open by this code.
5. Constant variable Declaration
Here we declare the one Constant wdFormatHTML and set their value 8.
we use this Constant when we save the word document into the html format by using the SaveAs method of declared word object.
To know more Word Enumerated Constants value, please Click Here
6. Create Scripting FileSystemObject
We create the Scripting FileSystemObject because we need this object when we want to list all files(word document file) of any folder for process.
7. Get the AbsolutePathName()
Here we set the actual path of string into the work_path variable by using the GetAbsolutePathName() method.This method returns the actual folder path where our script exist in the system.
8. Check and Create HTML Folder
Here we check the HTML Folder on the path.If HTML folder not exist then this code will create the HTML folder on the path.
9. Get all Files of specified path
GetFolder(path) this method return the specified folder and .Files returns the all files of specified folders.We Assign the returned files array to Files object
10. Iterate all files using "For Each loop"
In this code block we iterate all file of Files array object which set in previous step.FilesIdx is "For Each Loop" File type variable which represent the each file of Files Array in each loop iteration.
11. Check the File Extension
GetExtensionName(FileTypeVariable) return the Extension of specified file.If the extension of file will be "docx" or "doc" then if code will be executed otherwise loop will continue.
12. Get FileName
GetBaseName(FileObject) returns the base name or name of the file without extension.We need this file name because we save the html by the same file name.
13. Open the word file into Word Application
We use the Document.Open(FilePath) method to open the word file into the Word application.To use this method we need the Word.Application object.Here we open the Word File using the above objects and method and point the opened file to ObjDoc, we do this because if we want to perform any action or operation on opened document then we can use this ObjDoc Object to do that things.
14. Save Document into HTML format
Using the SaveAs method we save the opened document file into the HTML file on specified path.To use this method we need the Opened word file object.To save Word into HTML we pass the save file path and wdFormatHTML constant.This SaveAs method have more attribute which is optional and we can use all those as per requirements.
15. Close the open document
After saving the word document we need to close the opened word file.
To close current word file we use the .Close method.
To use this method we need the current active word file object.
16. Quit the Word Application Object
We need to close or quit the created word application object.To quit the word application object we use the .Quit method to close the word application.To use this method we need the word application object.
17. Save and Run Script file
Now save all the written code in the system using the VBS editor file save option.and copy the script file in that folder in which our all word document file exist.After move double click on VBscript file to run program code.
18. Opened Word Application
After run the VBscript program it open the word application editor and each document file one by one.Here you can see the sample open