| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Classic ASP/VBScript - reading word file by using word.application object
Code:
<%
Dim oDoc
Dim objFso
Dim colFiles
Dim curFile
Dim curFileName
Dim folderToScanExists
Dim folderToSaveExists
Dim objFolderToScan
'set some of the variables
folderToScanExists = False
folderToSaveExists = False
Const wdSaveFormat = 10 'for Filtered HTML output
'********************************************
'change the following to fit your system
Const folderToScan = "D:\amitweb"
Const folderToSave = "D:\ITS_RMS\images"
'********************************************
'Use FSO to see if the folders to read from
'and write to both exist.
'If they do, then set both flags to TRUE,
'and proceed with the function
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FolderExists(folderToScan) Then
folderToScanExists = True
Else
response.write "<script>alert('Folder to scan from does not exist!')</script>"
End If
If objFso.FolderExists(folderToSave) Then
folderToSaveExists = True
Else
response.write"<script>alert('Folder to copy to does not exist!', 48, 'File System Error');</script>"
End If
If (folderToScanExists And folderToSaveExists) Then
'get your folder to scan
Set objFolderToScan = objFso.GetFolder(folderToScan)
'put al the files under it in a collection
Set colFiles = objFolderToScan.Files
'create an instance of Word
Set objWord = CreateObject("Word.Application")
If objWord Is Nothing Then
response.write"<script>alert('Couldn't start Word.', 48, 'Application Start Error');<\script>"
Else
'for each file
For Each curFile in colFiles
'only if the file is of type DOC
If (objFso.GetExtensionName(curFile) = "doc") Then
'get the filename without extension
curFileName = curFile.Name
curFileName = Mid(curFileName, 1, InStrRev(curFileName, ".") - 1)
'open the file inside Word
objWord.Documents.Open objFso.GetAbsolutePathName(curFile)
'do all this in the background
objWord.Visible = False
'create a new document and save it as Filtered HTML
Set oDoc = objWord.ActiveDocument
oDoc.SaveAs folderToSave & curFileName & ".htm", wdSaveFormat
oDoc.Close
Set oDoc = Nothing
End If
Next
End If
'close Word
objWord.Quit
'set all objects and collections to nothing
Set objWord = Nothing
Set colFiles = Nothing
Set objFolderToScan = Nothing
End If
Set objFso = Nothing
%>
Last edited by Shadow Wizard : April 16th, 2008 at 03:24 AM. Reason: added [Code] and [/Code] tags around code please do that yourself next. |
|
#2
|
||||
|
||||
|
thanks for sharing the code with as, Amit.
in the future please use code tags and please put it in the Code Bank. also, I assume you checked the code and that it works. |
|
#3
|
|||
|
|||
|
Quote:
i am having a problem in running the code. it is giving me an error activex cannot create object. after searching on that problem i register the dll file. but my problem is not solved. can you please let me know the installation step or step in IIS which is giving me the problem. |
|
#4
|
||||
|
||||
|
Quote:
|
|
#5
|
|||
|
|||
|
hi
i m getting this Error Microsoft Word (0x800A175D) Could not open macro storage. at " objWord.Documents.Open objFso.GetAbsolutePathName(curFile) " position plz have a look and correct me. i have seen some result's from google , on which most of the ppl are saying , there is some setting on IIS "(IUSR account) " , wht exactly it is ? and wht i have to do for this error . Thank You, Mark ![]()
__________________
if you found this post is useful click (right side on this reply ) and agreeCoding Stuffs, web development help Thank You, ![]() KiranK |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Classic ASP/VBScript - reading word file by using word.application object |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|