Assigning the first row of a page to a variable.

S

Santa Claus

Hi, have a large document and want to be able to 'save as' a selected page
to a new document. The first row of each page has a heading (though it isnt
always formatted as a heading).

I want to assign the first row of a current page to a variabl to use in the
save as command. (I cant use the default save as name because I want to add
the date to the string).

I tried posting this last week, but dont think i made myself clear...hope
someone can help.

Regards
Santa
 
H

Helmut Weber

Hi,

first line or first paragraph?
Rows are parts of tables.

How do you select the page?

Are you able to save a page as a new document?

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
S

Santa Claus

Hi Helmut,

Sorry for the confusion, I'm wanting to select the first 'paragraph'.

The page to be selected will be the current page....on the screen with
cursor on it.

As for saving the page as a new document, I have code to copy the page into
a new document where i will save it then close it.

Thanks
 
H

Helmut Weber

Hi,

like this:

Dim sTmp As String
Selection.Bookmarks("\page").Select
Selection.Collapse
Selection.Expand unit:=wdParagraph
sTmp = Selection.Text

stmp is the part of text form the first paragraph,
which is on the actual page.

There was another posting by Jean-Guy Marcil,
which gets the text from the first paragraph on a page,
even it it starts on the page before.

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
S

Santa Claus

Thanks Helmut....much appreciated!!!!

Any idea when Jean-Guy Marcil made that post..I've had a look for
it.....would be very useful.

Thanks again!!!!
 
H

Helmut Weber

Hi Santa,

I have to use 3 different newsreaders and each shows
this or that, but hardly one shows all postings.

For Jean-Guy's solution, see:

http://tinyurl.com/e2dju

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jean-Guy Marcil

Helmut Weber was telling us:
Helmut Weber nous racontait que :
Hi,

like this:

Dim sTmp As String
Selection.Bookmarks("\page").Select
Selection.Collapse
Selection.Expand unit:=wdParagraph
sTmp = Selection.Text

stmp is the part of text form the first paragraph,
which is on the actual page.

There was another posting by Jean-Guy Marcil,
which gets the text from the first paragraph on a page,
even it it starts on the page before.

But, if you want the first line on the current page, even if the paragraph
starts on a preceding page, then try:

Dim PageRange As Range
Dim StartRange As Range
Dim LineStr As String

Set StartRange = Selection.Range

Set PageRange = ActiveDocument.Bookmarks("\Page").Range
PageRange.Select

PageRange.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
 
H

Helmut Weber

Hi Jean-Guy,

no need to try. :)

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jean-Guy Marcil

Helmut Weber was telling us:
Helmut Weber nous racontait que :
Hi Jean-Guy,

no need to try. :)

Touchy this morning (hum, afternoon for you!) ;-) !!!

The "try" was meant for Santa (So that I get my share of gifts this year...)

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

Santa Claus

Hi Helmut & Jean-Guy,

Your suggestions were most helpful! However, I end up with a square
character at the end of the string....which cuases an error when i try to
use the string as a file name.

I've tried clening the string using 'cleanstring', but this doesnt seem to
work. Any ideas?

Thanks
 
H

Helmut Weber

Hi Santa,

cut off the last character, like
myvar = Left(myvar, Len(myvar) - 1)

There may however be some other characters left,
which can't be used in a filename.

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

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