Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Document and Visual Basic: Movement Problems

Status
Not open for further replies.

mciing7912

Programmer
Jul 14, 2006
16
MX
HI guys, I tried to look into this forum something related to this but I couldn't so, here's my problem:

I created a VB application. This program evaluates what products a user has selected and based on that, open a word document previously created by me(template note).

in this word document, I have included all my warranty policies so, if a user just select the product 2, I open the document, search warranty text for product 1(it will be erased because I just need to leave warranty for product 1) and start to select the text belongs to this warranty(41 lines after header):

.Selection.Find.ClearFormatting
.Selection.Find.Text = "WARRANTY PRODUCT 1"
.Selection.Find.Replacement.Text = ""
.Selection.Find.Forward = True
.Selection.Find.Execute
.Selection.MoveDown Unit:=wdLine, Count:=41, Extend:=wdExtend
.Selection.Delete

the problem with this code is, in some cases deletes more than 41 lines or other cases less. I tested same code in different computers and each one has a different behavior.

has someone experimented this behavior???

also, in some cases, if your creating a word document and don't show the document in screen(WordReport.Application.Visible = True) at the beginning, this weird behavior is worst. obviously, I don't want to show the document until my program finishes its work because maybe, the user can press any key without intention...

thanks
 
Just a suggestion but instead of counting 41 lines, why not search for something at the start of line 41. Perhaps it works differently on other machines because of their default printer which would affect the page margins / page orientation and therefore the line count?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top