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, 08: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 02:24 AM. Reason: added [Code] and [/Code] tags around code please do that yourself next.

Reply With Quote
  #2  
Old April 16th, 2008, 02:26 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information
 
Join Date: Sep 2004
Location: Israel
Posts: 29,260 Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)  Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 3 Months 2 Weeks 2 Days 30 m 22 sec
Reputation Power: 2509
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, 02: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, 03:06 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information
 
Join Date: Sep 2004
Location: Israel
Posts: 29,260 Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 23rd Grade (Above 100000 Reputation Level)  Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2Folding Points: 587027 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 3 Months 2 Weeks 2 Days 30 m 22 sec
Reputation Power: 2509
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, 05:48 AM
markWilson markWilson is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2008
Posts: 508 markWilson User rank is First Lieutenant (10000 - 20000 Reputation Level)markWilson User rank is First Lieutenant (10000 - 20000 Reputation Level)markWilson User rank is First Lieutenant (10000 - 20000 Reputation Level)markWilson User rank is First Lieutenant (10000 - 20000 Reputation Level)markWilson User rank is First Lieutenant (10000 - 20000 Reputation Level)markWilson User rank is First Lieutenant (10000 - 20000 Reputation Level)markWilson User rank is First Lieutenant (10000 - 20000 Reputation Level)markWilson User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 15 h 42 m 22 sec
Reputation Power: 115
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

Microsoft Ajax CDN,
Twitter Games
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!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

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





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