Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine Line Position in a Word Doc.
Message
From
12/07/2006 08:44:13
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
11/07/2006 21:43:33
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01135560
Message ID:
01135644
Views:
18
This message has been marked as the solution to the initial question of the thread.
>I'm using automation to create a word doc from VFP 8 (Word version = 2002).
>I open an existing document, then add text to it. What I'd like to do is determine the current line number of the current page in the Word document so I can include a page break, if necessary. My code looks like this:
>
>loWord = CREATEOBJECT("Word.application")
>WITH loWord
>  .Documents.Open("DocToOpen.doc")
>
>  WITH .ActiveDocument
>    *Grab a reference to the existing text.
>    loSelection = .ActiveWindow.Selection
>    WITH loSelection
>      	*Add Customer name and billing address.
>      	.InsertAfter(lcCustName + CHR(13))
>      	.InsertAfter(lcAddr1 + CHR(13))
>	IF !EMPTY(lcAddr2)
>	    .InsertAfter(lcAddr2 + CHR(13))
>	ENDIF
>	.InsertAfter(lcCityStZip + CHR(13) + CHR(13))
>
>	*Add salut, and default text
>       	.InsertAfter(lcSalut + "," + CHR(13))
>        .InsertAfter("Some introductory text goes here:" + CHR(13))
>      	*Then move down one line.
>      	.MoveDown(,1,)
>	*Scan the cursor and add items as necessary.
>	SELECT TestCursor
>	SCAN
>	    *Check where we are on the page...need a minimum of 4 lines.
>	    If (There isn't enough space, this is the code I need)
>                *Add a page break.
>		.InsertBreak(0)			
>	    Endif
>	    .InsertAfter(FieldValue1 + CHR(13))
>	    .InsertAfter(FieldValue2 + CHR(13))
>	    .InsertAfter(FieldValue3 + CHR(13))
>	    .InsertAfter(FieldValue4 + CHR(13))				
>        ENDSCAN
>     ENDWITH
>  ENDWITH
>ENDWITH
>
>I've tried a whole series of object and method combinations but haven't been able to locate the one for line numbers. Paragraphs, yes, but line numbers, no. I also realize there are other ways to do what I'm trying to do. I'm open to any suggestions, as long as they move me in the right direction. Thanks in advance.

Tim,
I don't know either:) However you can do it in another way. You could record current page before insertion, insert lines, check on what page, if increased moveup and insert pagebreak. In pesudocode:
lnOnPage = loWord.Selection.Information(wdActiveEndPageNumber)
    .InsertAfter(FieldValue1 + CHR(13))
    .InsertAfter(FieldValue2 + CHR(13))
    .InsertAfter(FieldValue3 + CHR(13))
if loWord.Selection.Information(wdActiveEndPageNumber) > m.lnOnPage
.MoveUp(,3)
.InsertBreak(0)
* go to end
endif
    .InsertAfter(FieldValue4 + CHR(13))
PS: You're inserting lines with CR. So in fact aren't Lines = Paragraphs?
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform