Problem while processing word file with word instance from vb.net

J

Jack

Hi,

I have job to verify data available in doc/rtf files. For verification
I am opening file in the instance of WinWord(MS Word) application. I
do the process page by page for detailed comparison.

The actual problem starts when I shift cursor to any pages using
following code :

MsWord.Selection.GoTo(Word.WdGoToItem.wdGoToPage, _
Word.WdGoToDirection.wdGoToAbsolute, IntCounter)

Here [ IntCounter ] is variable for page counter.

Statement executes perfectly and cursor sifted to exact starting
position of page. But the first line of the page shifted at the
bottom of the upper page. As result such data not verified.
 
J

Jean-Guy Marcil

Jack said:
Hi,

I have job to verify data available in doc/rtf files. For verification
I am opening file in the instance of WinWord(MS Word) application. I
do the process page by page for detailed comparison.

The actual problem starts when I shift cursor to any pages using
following code :

MsWord.Selection.GoTo(Word.WdGoToItem.wdGoToPage, _
Word.WdGoToDirection.wdGoToAbsolute, IntCounter)

Here [ IntCounter ] is variable for page counter.

Statement executes perfectly and cursor sifted to exact starting
position of page. But the first line of the page shifted at the
bottom of the upper page. As result such data not verified.

Maybe you are using a different printer from the one that was used when
creating the files.
Word reflows the text differently than when it was first set?

Do you observe this behaviour with every single page of every single
document you process?
What Word version are you using?
 
J

Jack

Well I am using MSWord 2002.

Now I came to know that this error occured on every pc with same file
and when I open doc file normally it shows data in proper way but when
i open document through codding MS Word misbehave.

Jack said:
I have job to verify data available in doc/rtf files. For verification
I am opening file in the instance of WinWord(MS Word) application. I
do the process page by page for detailed comparison.
The actual problem starts when I shift cursor to any pages using
following code :
MsWord.Selection.GoTo(Word.WdGoToItem.wdGoToPage,  _
Word.WdGoToDirection.wdGoToAbsolute, IntCounter)
Here [ IntCounter ] is variable for page counter.
Statement executes perfectly and cursor sifted to exact starting
position of page.  But the first line of the page shifted at the
bottom of the upper page.  As result such data not verified.

Maybe you are using a different printer from the one that was used when
creating the files.
Word reflows the text differently than when it was first set?

Do you observe this behaviour with every single page of every single
document you process?
What Word version are you using?
 
J

Jack

My job is like find tag and then compare value associated with that
tav with database.

Well I am using MSWord 2002 and validate data using find.execute
function of word application. So I do not worry about line or page.

Here is sample code:

If objDoctorCheckSpecification.PatientID Then
MsWord.Selection.HomeKey(Word.WdUnits.wdStory)
If MsWord.Selection.Find.Execute("ACCOUNT NO:") Then

Call subSelectUpToEndofLine() ' This function
select line from the current possition to end of the line

If MsWord.Selection.Text.Trim <> dtblPatient.Rows
(0)("Pno").ToString Then
objLogCollecton.LogComment.Add(New clsLog
("Error : Patient No Mismatch in file."))
End If
Else
objLogCollecton.LogComment.Add(New clsLog("Error :
ACCOUNT NO: Tag not found in file."))
End If
End If


Now I came to know that this error occured on every pc with same file
and when I open doc file normally it shows data in proper way but when
i open document through codding MS Word misbehave.

Thanks,
 
J

Jean-Guy Marcil

Jack said:
My job is like find tag and then compare value associated with that
tav with database.

Well I am using MSWord 2002 and validate data using find.execute
function of word application. So I do not worry about line or page.

Here is sample code:

If objDoctorCheckSpecification.PatientID Then
MsWord.Selection.HomeKey(Word.WdUnits.wdStory)
If MsWord.Selection.Find.Execute("ACCOUNT NO:") Then

Call subSelectUpToEndofLine() ' This function
select line from the current possition to end of the line

If MsWord.Selection.Text.Trim <> dtblPatient.Rows
(0)("Pno").ToString Then
objLogCollecton.LogComment.Add(New clsLog
("Error : Patient No Mismatch in file."))
End If
Else
objLogCollecton.LogComment.Add(New clsLog("Error :
ACCOUNT NO: Tag not found in file."))
End If
End If


Now I came to know that this error occured on every pc with same file
and when I open doc file normally it shows data in proper way but when
i open document through codding MS Word misbehave.

I am still not sure what you are doing and what the exact problem is.

Can you post the "End of line" function? The problem might be in that
procedure.
 
J

Jack

Private Sub subSelectUpToEndofLine()
MsWord.Selection.MoveRight(Unit:=Word.WdUnits.wdCharacter,
Count:=1)
MsWord.Selection.EndKey(Unit:=Word.WdUnits.wdLine,
Extend:=Word.WdMovementType.wdExtend)
End Sub
 
D

Doug Robbins - Word MVP

A better way would be to use

Dim eol As Range
Set eol = Selection.Range
eol.End = Selection.Bookmarks("\line").Range.End
eol.Start = eol.Start + 1
eol.Select


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Private Sub subSelectUpToEndofLine()
MsWord.Selection.MoveRight(Unit:=Word.WdUnits.wdCharacter,
Count:=1)
MsWord.Selection.EndKey(Unit:=Word.WdUnits.wdLine,
Extend:=Word.WdMovementType.wdExtend)
End Sub
 
J

Jack

thanks Doug Robbins.

I have added "subSelectUpToEndofLine" procedure code on the request of
Jean-Guy. Here problem is not for selection of content from current
cursor position to end of line but other as I have defined before.
 
D

Doug Robbins - Word MVP

It is not clear what you mean by "other"

It might be better to tell us what you need to do, rather than the problem
that you are encountering with the way that you are trying to do it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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