PDA

Click to See Complete Forum and Search --> : How do i know which line number i'm on in Word


ZeBula8
Jan 28th, 2005, 03:13 PM
As i write to my Word document using VBA,
how can i find out which line i am writing to?

thanks in advance,

RobDog888
Jan 29th, 2005, 04:16 PM
You probably need to keep track of the number of line breaks or carriage returns
your entering. Can you give a little more info on what your trying to do?

You may be able to use the .Find method, etc.

ZeBula8
Jan 29th, 2005, 06:10 PM
Thanks Robb, I've found out what I've asked.

I have an Access database that has a contacts table.

Within Access, I create a Word object reference that writes to a Word document, essentially creating a listing - I've coded it so that the Word document has 2 columns.

The company has always done this in Word, so I don't want to use the reports in Access for this.

And actually, the Word document is created quite fast.

The problem I'm having is a bit of a grouping thing and the columns come into the picture here.

There are five groups of contacts - each group may have about 10 to 20 contacts. I want to keep each contact together so that a contact does not split across the column.

This is why I need to know which line I'm on so I can calculate when to make a column break so that the contact information is kept together. Each contact has from 5 to 10 lines each.

The tricky part is that with 2 columns on the document the line numbering continues as follows:

First column can contain 1 to 50 lines approximately, based on my margins.
Second column can contain 51 to 100 approximately, based on my margins.

So in my loop that actually does the writing to Word, I get the current line number and find out if I have enough lines to write the next contact or create a column break and then resume the writing of the contact to the Word document.


By the way, you are able to use this line of code to get the current line the cursor is on (where objWord is my Word application object reference):


Dim CurrentLineNumber as long

CurrentLineNumber = objWord.Selection.Range.Information (wdFirstCharacterLineNumber)

RobDog888
Jan 29th, 2005, 09:35 PM
Thanks, I havent had the need yet to get the line number, but it nice to have for future reference.

:thumb: