Reading a Word Doc Line by Line in VBA 
Author Message
 Reading a Word Doc Line by Line in VBA

Does anyone have code that can read in a Microsoft Word Document line by
line?
I am working in VBA and Access 97. I have figured out how to get to the
Document Object but cannot
figure out the method to read through the file line by line. The code
below is as far as I have gotten.
VBA does not recognize the wdGoToLine and wdGoToFirst constants.

=================== Code Follows =====================
Private Sub TestNewLooping_Click()

Dim wdObject As Object
Dim lineObject As Object
Dim filespec As String

Set wdObject = CreateObject("Word.Application")
wdObject.Visible = True

lineObject = wdObject.Documents.Goto(wdGoToLine, wdGoToFirst) <--- VBA
does not
recognize these Constants :(

MsgBox lineObject.Text
Set wdObject = Nothing
End Sub

=============================================================
Any hits or clues will be greatly appreciated,

-Jacque



Sun, 10 Mar 2002 03:00:00 GMT  
 Reading a Word Doc Line by Line in VBA
I'd suggest getting a Word VBA book such as those listed at
http://www.standards.com/users/kaikow/
Quote:

> Does anyone have code that can read in a Microsoft Word Document line by
> line?
> I am working in VBA and Access 97. I have figured out how to get to the
> Document Object but cannot
> figure out the method to read through the file line by line. The code
> below is as far as I have gotten.
> VBA does not recognize the wdGoToLine and wdGoToFirst constants.

> =================== Code Follows =====================
> Private Sub TestNewLooping_Click()

> Dim wdObject As Object
> Dim lineObject As Object
> Dim filespec As String

> Set wdObject = CreateObject("Word.Application")
> wdObject.Visible = True

> lineObject = wdObject.Documents.Goto(wdGoToLine, wdGoToFirst) <--- VBA
> does not
> recognize these Constants :(

> MsgBox lineObject.Text
> Set wdObject = Nothing
> End Sub

> =============================================================
> Any hits or clues will be greatly appreciated,

> -Jacque



Sun, 10 Mar 2002 03:00:00 GMT  
 Reading a Word Doc Line by Line in VBA
Hi Jacque,

Lines in a Word document are not objects. You have to work with the
Selection or Range objects. For the Selection object, try something like
this:

Selection.GoTo What:=wdGoToLine, Which:=wdGoToFirst
ActiveDocument.Bookmarks("\Line").Range.Select
MsgBox Selection.Text

Of course, you may have to modify it to refer to the Word application object
you have created as this is the syntax used if you do it directly from Word
VBA.

Hope this helps.

| Does anyone have code that can read in a Microsoft Word Document line by
| line?
| I am working in VBA and Access 97. I have figured out how to get to the
| Document Object but cannot
| figure out the method to read through the file line by line. The code
| below is as far as I have gotten.
| VBA does not recognize the wdGoToLine and wdGoToFirst constants.
|
| =================== Code Follows =====================
| Private Sub TestNewLooping_Click()
|
| Dim wdObject As Object
| Dim lineObject As Object
| Dim filespec As String
|
| Set wdObject = CreateObject("Word.Application")
| wdObject.Visible = True

| lineObject = wdObject.Documents.Goto(wdGoToLine, wdGoToFirst) <--- VBA
| does not
| recognize these Constants :(
|
| MsgBox lineObject.Text
| Set wdObject = Nothing
| End Sub
|
| =============================================================
| Any hits or clues will be greatly appreciated,
|
| -Jacque
|



Mon, 11 Mar 2002 03:00:00 GMT  
 Reading a Word Doc Line by Line in VBA
hi,

   i uses paragraphs to move down the entire word document.

dim para as paragraph
for each para in ActiveDocument.paragraphs
  msgbox para
next para

   you should be able to move down the document.hope it helps.
regards,
James


Quote:
> I'd suggest getting a Word VBA book such as those listed at
> http://www.standards.com/users/kaikow/




Quote:
> > Does anyone have code that can read in a Microsoft Word Document
line by
> > line?
> > I am working in VBA and Access 97. I have figured out how to get to
the
> > Document Object but cannot
> > figure out the method to read through the file line by line. The
code
> > below is as far as I have gotten.
> > VBA does not recognize the wdGoToLine and wdGoToFirst constants.

> > =================== Code Follows =====================
> > Private Sub TestNewLooping_Click()

> > Dim wdObject As Object
> > Dim lineObject As Object
> > Dim filespec As String

> > Set wdObject = CreateObject("Word.Application")
> > wdObject.Visible = True

> > lineObject = wdObject.Documents.Goto(wdGoToLine, wdGoToFirst) <---
VBA
> > does not
> > recognize these Constants :(

> > MsgBox lineObject.Text
> > Set wdObject = Nothing
> > End Sub

> > =============================================================
> > Any hits or clues will be greatly appreciated,

> > -Jacque

Sent via Deja.com http://www.deja.com/
Before you buy.


Tue, 12 Mar 2002 03:00:00 GMT  
 Reading a Word Doc Line by Line in VBA

Quote:

> Does anyone have code that can read in a Microsoft Word Document line by
> line?

Microsoft has (or had, my printout is dated may 10. 1999) a document in the
online Knowledge Base called "WD97: Sample code to increment through a
document line by line"

Something like this has worked for me:

   ' Move the insertion point to the beginning of the document.
      Selection.HomeKey Unit:=wdStory, Extend:=wdMove
      ' Loop number of lines in document.
       x = ActiveDocument.BuiltInDocumentProperties("NUMBER OF LINES")
      For i = 1 To x
         ' Select a line.
         ActiveDocument.Bookmarks("\LINE").Select
         Indhold = Trim(Selection)

        'here you can do whatever you want to the line contained in the var.
Indhold

        ' Display line number. Just for test reasons, don't do it on your
150.000 lines new book manuscript ;-)
         MsgBox "Line: " & i
         ' Move to next line.
         Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
      Next i

--
Med venlig hilsen / Kind regards
from ?lstykke, Denmark

Kim

home: http://home2.inet.tele.dk/kim-niel/
business: http://viviankisoft.hypermart.net/



Sat, 16 Mar 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Search thru Word Doc line by line

2. i want to read line by line from a word document

3. VBA to remove lines from mail merge doc

4. Print Word doc. from command line

5. Delete Line in Word Doc

6. Adding Bulleted lines in a Word Doc

7. reading mail message body line by line

8. Read a MultiLine textbox line by line?

9. Read LINE by LINE in RTF

10. Reading from a file line for line

11. Help : Reading files line by line !

12. reading input line by line

 

 
Powered by phpBB® Forum Software