Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 15th, 2008, 09:29 AM
amit_jadhav9 amit_jadhav9 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 amit_jadhav9 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 34 m 29 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old April 16th, 2008, 03:26 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 48th Plane (28500 - 28999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 28,838 Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)  Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 3 Months 2 Weeks 1 Day 14 h 30 m 10 sec
Reputation Power: 2389
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.

Reply With Quote
  #3  
Old July 17th, 2008, 03:25 AM
ndehdia2001 ndehdia2001 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 1 ndehdia2001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by amit_jadhav9
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 
%>


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.

Reply With Quote
  #4  
Old July 17th, 2008, 04:06 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 48th Plane (28500 - 28999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 28,838 Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)  Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 3 Months 2 Weeks 1 Day 14 h 30 m 10 sec
Reputation Power: 2389
Quote:
Originally Posted by ndehdia2001
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.
you need to install Word on the server. it's not one single DLL file.

Reply With Quote
  #5  
Old April 15th, 2009, 06:48 AM
markWilson markWilson is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Posts: 253 markWilson User rank is Second Lieutenant (5000 - 10000 Reputation Level)markWilson User rank is Second Lieutenant (5000 - 10000 Reputation Level)markWilson User rank is Second Lieutenant (5000 - 10000 Reputation Level)markWilson User rank is Second Lieutenant (5000 - 10000 Reputation Level)markWilson User rank is Second Lieutenant (5000 - 10000 Reputation Level)markWilson User rank is Second Lieutenant (5000 - 10000 Reputation Level)markWilson User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 16 h 24 m 19 sec
Reputation Power: 82
Exclamation

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 agree

Coding Stuffs,

web development help
Thank You,
KiranK

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Classic ASP/VBScript - reading word file by using word.application object


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek