sja13
Professional Idiot
- Local time
- Today, 17:08
- Joined
- May 3, 2017
- Messages
- 63
I have the following code which I hoped would read an entire (short) document, but it doesn't- the problem is commented in the code. Can ayone help?
Code:
Sub ReadWordDoc()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim strWordFile As String
Dim varRes As Variant
strWordFile = "Z:\A file which exists.docx"
'*
'** Ensure only one instance of Word.
'*
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
'*
'** Open the Word document.
'*
Set wdDoc = wdApp.Documents.Open(strWordFile)
wdApp.Visible = True
'*
'** Select all the text (by inspection this
'** seems to happen)
'*
wdDoc.Select
'*
'** Next bit just gives part of the document.
'** From inspection of Word, I get
'** 40 words,
'** 210 characters (243 inc spaces),
'** 6 paragraphs and
'** 8 lines.
'** The part I get splits mid word.
'** None of the above stats seem to be
'** 'magic numbers;.
'*
varRes = wdDoc.Range
'*
'** Tidy up.
'*
wdDoc.Close
wdApp.Quit
End Sub