|
-
Dec 14th, 2005, 06:53 PM
#1
Thread Starter
Frenzied Member
word automation
Hey,
How can I read a word document line by line using automation?
Links to examples would be great.
thanks,
Don't anthropomorphize computers -- they hate it
-
Dec 14th, 2005, 07:06 PM
#2
Re: word automation
Here is some pseudo code:
Add a Reference to Word Library, and make the appropriate changes (ie Application will become your Word Object reference)
VB Code:
Sub ReadWord()
Dim strArr() As String
Dim intCount As Integer
Dim intIdx As Integer
'Capture the Word Text
ActiveDocument.Select
'Load an Array with each line
strArr() = Split(Selection.Text, vbCr)
intCount = UBound(strArr) - 1
For intIdx = 0 To intCount
MsgBox strArr(intIdx)
Next
End Sub
Last edited by Bruce Fox; Dec 14th, 2005 at 07:14 PM.
-
Dec 14th, 2005, 07:10 PM
#3
Re: word automation
Here is a working version that dosn't require a Library Reference:
(Just have the instance of Word open)
VB Code:
Option Explicit
'Note: NO reference to MS Word Object Library x.x is required in this example
Private Sub Form_Load()
Dim objWord As Object
Dim strArr() As String
Dim intCount As Integer
Dim intIdx As Integer
On Error GoTo Err_Handler
Set objWord = GetObject(, "Word.Application")
'Capture the Word Text
objWord.ActiveDocument.Select
'Load an Array with each line
strArr() = Split(objWord.Selection.Text, vbCr)
intCount = UBound(strArr) - 1
For intIdx = 0 To intCount
MsgBox strArr(intIdx)
Next
Set objWord = Nothing
Exit Sub
Err_Handler:
If Not (objWord Is Nothing) Then Set objWord = Nothing
MsgBox "Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description, vbOKOnly + vbCritical, "Error!"
End Sub
Last edited by Bruce Fox; Dec 14th, 2005 at 07:14 PM.
-
Dec 14th, 2005, 07:58 PM
#4
Thread Starter
Frenzied Member
Re: word automation
Thanks a lot.
How about going through each page in the document?
Don't anthropomorphize computers -- they hate it
-
Dec 14th, 2005, 08:18 PM
#5
Re: word automation
Are the pages seperated by Page Breaks?
-
Dec 14th, 2005, 08:54 PM
#6
Thread Starter
Frenzied Member
Re: word automation
yes, each page is separated by a page break.
Don't anthropomorphize computers -- they hate it
-
Dec 14th, 2005, 09:03 PM
#7
Re: word automation
You might be able to get some ideas here:
http://support.microsoft.com/?kbid=293861
-
Dec 14th, 2005, 09:48 PM
#8
Thread Starter
Frenzied Member
Re: word automation
I've seen this article. I don't have any section breaks. I only have page breaks in my document. I have no control over the creation of the document, I just have to import the data.
Don't anthropomorphize computers -- they hate it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|