Option Explicit REM We use "Option Explicit" to help us check for coding mistakes REM the Word Application Dim objWord REM the path to the Word file Dim wordPath REM the document we are currently reading data from Dim currentDocument REM the number of Words in the current document Dim numberOfWords Dim i Dim objDialog Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*" objDialog.FilterIndex = 1 objDialog.InitialDir = "C:\" intResult = objDialog.ShowOpen If intResult = 0 Then Wscript.Quit Else Wscript.Echo objDialog.FileName End If REM where is the Word file located? wordPath = "C:\Documents and Settings\sapuser\Desktop\harry.doc" WScript.Echo "Extract Data from " & wordPath REM Create an invisible version of Microsoft Word Set objWord = CreateObject("Word.Application") REM don't display any messages about documents needing to be converted REM from old Word file formats objWord.DisplayAlerts = 0 REM open the Word document as read-only REM open (path, confirmconversions, readonly objWord.Documents.Open wordPath, false, true REM Access the document Set currentDocument = objWord.Documents(1) REM How many words are in the document NumberOfWords = currentDocument.words.count WScript.Echo "There are " & NumberOfWords & " words " & vbCRLF For i = 1 to NumberOfWords WScript.Echo currentDocument.words(i) Next REM Close the document currentDocument.Close REM Free memory used to store the document object Set currentDocument = Nothing REM exit Microsoft Word objWord.Quit Set objWord = Nothing
NumberOfWords = currentDocument.words.count
For i = 1 to NumberOfWords<br /> WScript.Echo currentDocument.words(i)<br /> Next<br />
Paragraphs
For Each p In currentDocument.Paragraphs WScript.Echo p.Range.Text Next p
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)