Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 21st, 2013, 02:42 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Counting line numbers in a section

I'm trying to get the number of lines in a section. I'd rather not loop through the lines if at all possible. So I tried using the following Code snippet:
Code:
Set MySection = ActiveDocument.Sections(s)
MySection.Range.Select
Debug.Print "Section"; s; " starts in line"; Selection.Information(wdFirstCharacterLineNumber)
I'm passing in a section number (s) to this procedure. Unfortunately the method returns only the line number within the section of the first character in the selection. Since I'm selecting the whole range, this will always be 1. (I suppose it could have been 0, but ....nah, don't go there ;-)

Has anybody else solved this problem?

Thanks,

Tony
Reply With Quote
  #2 (permalink)  
Old September 21st, 2013, 11:44 PM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi Tony

Do you want to get the number of lines in each section?

You can try using the Selection.Range.Start and Selection.Range.End to know the start and end positions in each Section

This can help you find the no of lines

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #3 (permalink)  
Old September 22nd, 2013, 09:51 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Line count in section

Thanks for the pointer Shasur,

The Start and End position are character positions (within the document, to be sure), but there is no easy way to turn them into line numbers. At the moment I'm stuck with building a separate table to track line numbers, and then iterating line-by-line over each section in turn (Yecch).

Does anyone have any (relatively) easy way to do as Shasur suggests, and convert character positions to line numbers? (Variable length lines, of course, along with Section Breaks)

Tony
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Section Line Not to Print bharatsaboo Crystal Reports 2 November 4th, 2007 11:45 AM
Line Item Numbers needed Bob Hansen Access VBA 1 May 16th, 2006 03:21 PM
Counting number of spaces in a line Suomi Access VBA 3 September 9th, 2005 03:34 PM
[?] Line numbers in VBA Chantale Access VBA 6 November 3rd, 2004 07:17 AM
counting record numbers in a loop sniffer Classic ASP Basics 2 October 21st, 2004 12:49 PM



All times are GMT -4. The time now is 12:04 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.