VBScript to read a word doc

J

jam

Hi All,


I need a help. my code is

Line1 Const ForReading = 1, ForWriting = 2

Line2 Dim fso, MyFile, ReadLineTextFile

Line3 Set objWord = CreateObject("Word.Application")

Line4 objWord.Visible = True

Line5 Set objFile1 = objWord.Documents.Open("E:\myWord.doc")

Line6 str = objFile1.ReadLine

In This code iam getting unrecoverable error. In Line 6 saying Object
does't support this property or method. Please help me in this. I want
to search a string in the word document.

Thanks,
Ruby
 
T

Tony Jollans

You seem to be confusing working with text files and documents, and I don't
really see what you're trying to do but to search a word document, try
something like

With objFile1.Content
If .Find.Execute("whatever you want") then .select
end with

I would look at Word Help for more information.
 
J

jam

You seem to be confusing working with text files and documents, and I don't
really see what you're trying to do but to search a word document, try
something like

    With objFile1.Content
        If .Find.Execute("whatever you want") then .select
    end with

I would look at Word Help for more information.

--
Enjoy,
Tony

 www.WordArticles.com















- Show quoted text -

Hi Tony,

Thanks a lot for your help. iam done with the code below. I am using
".Paragraphs.Count" in the for loop
but i am never aware of it. only thing is i found it through google.
My question is where can i find those stuff. i had searched in some
reputed VB scripts books i could't find. is google only the way. I
think every body has this question in mind. kindly reply me.




Public Function String_Search(strExpectedString, strFilePath)
Set wrdApp = CreateObject("Word.Application")
wrdApp.DisplayAlerts = True
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(strFilePath, 1, True)
Dim blnFlag
With wrdDoc
blnFlag = False
For p = 1 To .Paragraphs.Count
startRange = .Paragraphs(p).Range.Start
endRange = .Paragraphs(p).Range.End
Set tRange = .Range(startRange, endRange)
tRange.Find.Text = strExpectedString
tRange.Find.Execute
If (tRange.Find.Found) Then
blnFlag = True
Exit For
End If
Next
End With
If( blnFlag = True) Then
Reporter.ReportEvent micPass,"Check for String", "The Expected
String Was Found in the specified document"
Else

Reporter.ReportEvent micFail,"Check for String", "The Expected
String Was Not Found in the specified document"
End If
wrdApp.Quit 0
End Function
 
T

Tony Jollans

There is no one place to look - the subject is too broad. In this case,
although you are using VBScript, you are trying to access Word documents
within it using the Word object model, so that would be where to look. For
formal documentation - what there is of it, and for what little it's worth -
msdn (perhaps start here:
http://msdn.microsoft.com/en-gb/office/aa905482.aspx) and/or technet are a
starting point. For a different view, see the Word MVPs site at
http://word.mvps.org/FAQs/MacrosVBA/index.htm.

--
Enjoy,
Tony

www.WordArticles.com

You seem to be confusing working with text files and documents, and I
don't
really see what you're trying to do but to search a word document, try
something like

With objFile1.Content
If .Find.Execute("whatever you want") then .select
end with

I would look at Word Help for more information.

--
Enjoy,
Tony

www.WordArticles.com















- Show quoted text -

Hi Tony,

Thanks a lot for your help. iam done with the code below. I am using
".Paragraphs.Count" in the for loop
but i am never aware of it. only thing is i found it through google.
My question is where can i find those stuff. i had searched in some
reputed VB scripts books i could't find. is google only the way. I
think every body has this question in mind. kindly reply me.




Public Function String_Search(strExpectedString, strFilePath)
Set wrdApp = CreateObject("Word.Application")
wrdApp.DisplayAlerts = True
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(strFilePath, 1, True)
Dim blnFlag
With wrdDoc
blnFlag = False
For p = 1 To .Paragraphs.Count
startRange = .Paragraphs(p).Range.Start
endRange = .Paragraphs(p).Range.End
Set tRange = .Range(startRange, endRange)
tRange.Find.Text = strExpectedString
tRange.Find.Execute
If (tRange.Find.Found) Then
blnFlag = True
Exit For
End If
Next
End With
If( blnFlag = True) Then
Reporter.ReportEvent micPass,"Check for String", "The Expected
String Was Found in the specified document"
Else

Reporter.ReportEvent micFail,"Check for String", "The Expected
String Was Not Found in the specified document"
End If
wrdApp.Quit 0
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top