Selecting first line of a page

S

Santa Claus

Second question, sorry to be cheeky.

Whats the line of code to assign the first row of a page or first row of a
document to a variable?

Thanks
 
J

Jean-Guy Marcil

Santa Claus was telling us:
Santa Claus nous racontait que :
Second question, sorry to be cheeky.

Whats the line of code to assign the first row of a page or first row
of a document to a variable?
Except with Word 2003 where there is a Line collection that is kind of
difficult to use, there are no "line" object in VBA.

Would that line always be a one-line paragraph?
How would you determine the page?
What are you trying to do?


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Santa Claus

Hi,

The code to select the first line on the current page will do. The first
line is always the heading (though not always formatted as a heading). I'm
wanting to grab this text to assign to a variable.

( I will then be using the variable as the new document name when i 'save
as').

Thanks for your help, I really do appreciate it.
 
S

Santa Claus

I should have mentioned that the cursor would be on the current page that i
would be working with.
 
J

Jean-Guy Marcil

Santa Claus was telling us:
Santa Claus nous racontait que :
Hi,

The code to select the first line on the current page will do. The
first line is always the heading (though not always formatted as a
heading). I'm wanting to grab this text to assign to a variable.

( I will then be using the variable as the new document name when i
'save as').

Try this:

Dim ParaRange As Range
Dim StartRange As Range
Dim LineStr As String

Set StartRange = Selection.Range

Set ParaRange = ActiveDocument.Bookmarks("\Page").Range.Paragraphs(1).Range
ParaRange.Select

ParaRange.Collapse wdCollapseStart

LineStr = ActiveDocument.Bookmarks("\Line").Range.Text

MsgBox LineStr

StartRange.Select


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top