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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP Word Automation - Finding/Counting Line Numbers

Status
Not open for further replies.

Goofus828

Programmer
Nov 9, 2005
127
US
Hi all,

I have a project that needs to generate a letter for client information. I am using VFP 9 and Word 2013

The letter format is as follows:
Date
Salutation
Body
Account Information ( 2-3 lines ) varying between 1 and 30 accounts
Closing
Signature Graphic
Signature block

I know the Body of the letters stops at line number 25 or 26.
Account information itself could vary from 2 to 3 lines. And I can have any number of accounts, current max is 28.

If there is a 3rd account, then the Closing, Signature Graphic and Signature Block needs to go on the next page otherwise it is split over the first and second pages. Does not look professional.

My challenge is how do I find the current line number in the Word document so I can determine when to place the Closing and signatures stuff on the next page.

I cannot use a VFP variable because the salutation could vary in lengths from 4 to 5 lines. Account information could vary between 2 and 4 lines.

i need a way to count the lines of text as I write them to the word document. This count will determine what I do next.

I use oRange.InsertAfter('text') to write the text.
oWord.SELECTION.EndKey(wdStory) to go to the end of the page.
If any of that helps.

Thanks in advance.




 
Tamar, I have seen this before and see no reference to Line Number property.

Thanks.
 
Yeah, and printer drivers too. Word queries the printer driver to decide how to lay out a page.

I think, instead of line numbers, Paragraphs would be better. Conveniently, Word has a Paragraphs collection.
 
The line numbers are not meaningless in this project. I know the that the first 3 paragraphs are static, the font and point size are consistent what I do not know is the number of accounts that the client has. If the client has 2 accounts then I know everything will fit on one page, if the client has 3 accounts then I know the closing will spill to the 2nd page. If the client has 14 accounts then there are 3 pages and so on and so on.
 
But you are presumably controlling the process from a VFP application. In which case, you do know the number of accounts. Or, at least, you should be able to determine that figure very easily from your FoxPro code.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
In fact. Vilhelm-Ion ahs already given you a good solution.

Assuming you are building the document line by line, then to get the current line number (relative to the page), you just need to look at [tt]Selection.Information(10)[/tt].

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Just following up my previous comment, here is a very simple example of how you can find the line number. I'm assuming you have an object reference to Word in loWord.

[tt]loWord.Selection.TypeText("First client info")
loword.Selection.TypeParagraph
loWord.Selection.TypeText("Second client info")
loword.Selection.TypeParagraph
lnLines = loWord.Selection.Information(10)[/tt]

[tt]lnLines[/tt] will now contain the required line number, which you can interrogate in VFP in any way you like.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top