Results 1 to 4 of 4

Thread: How do i know which line number i'm on in Word

  1. #1

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Resolved How do i know which line number i'm on in Word

    As i write to my Word document using VBA,
    how can i find out which line i am writing to?

    thanks in advance,
    Last edited by ZeBula8; Jan 29th, 2005 at 07:11 PM. Reason: Resolved

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do i know which line number i'm on in Word

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: How do i know which line number i'm on in Word

    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):

    Code:
    Dim CurrentLineNumber as long
    
    CurrentLineNumber = objWord.Selection.Range.Information (wdFirstCharacterLineNumber)

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do i know which line number i'm on in Word

    Thanks, I havent had the need yet to get the line number, but it nice to have for future reference.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width