Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

Mondays are tough

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dr. M - 18 Jul 2005 16:36 GMT
This is a dumb question obviously [it's Monday] but how do I determine if my
cursor is at the last line of the document, or end of file?

Thank you so much.
Signature

Dr. M

Anne Troy - 18 Jul 2005 16:43 GMT
How do you determine? Or how do you get it there? You can be sure it's there
by hitting Ctrl+End.
*******************
~Anne Troy

www.OfficeArticles.com

> This is a dumb question obviously [it's Monday] but how do I determine if my
> cursor is at the last line of the document, or end of file?
>
> Thank you so much.
Jonathan West - 18 Jul 2005 16:51 GMT
> This is a dumb question obviously [it's Monday] but how do I determine if
> my
> cursor is at the last line of the document, or end of file?
>
> Thank you so much.

Not a dumb question. Others have asked it before you. Take a look here

Determine whether the insertion point is located at the end of a document
http://www.word.mvps.org/FAQs/MacrosVBA/SelectionAtEndOfDoc.htm

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org 

Dr. M - 18 Jul 2005 16:52 GMT
Thank you for your response. How to determine if the line I'm on is the last
line. Here is the code I have so far, right now I have to manually put an X
in the first line to get it to quit, when I would rather have it just check
to see if it's on the last line or not of the entire document:

Sub line99()
Do While Selection <> "X"
'Test character for dash in position one
   Selection.MoveDown Unit:=wdLine, Count:=1
   Selection.HomeKey Unit:=wdLine
   Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection <> "-" Then
'Line backspace
   Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
   Selection.TypeBackspace
End If
Loop

End Sub
Signature

Dr. M

> This is a dumb question obviously [it's Monday] but how do I determine if my
> cursor is at the last line of the document, or end of file?
>
> Thank you so much.
Helmut Weber - 18 Jul 2005 17:14 GMT
Hi

like this, unless someone shows me, what is wrong:

Public Function Lastline() As Boolean
Dim rngTmp As Range
Set rngTmp = Selection.Range
rngTmp.End = Selection.Range.End
Selection.MoveDown
If Selection.Range.End > rngTmp.End Then
  Lastline = False
  Else
  Lastline = True
End If
End Function

Sub testLast()
MsgBox Lastline
End Sub

The insertion point doesn't move,
if it is in the last line.

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Jonathan West - 18 Jul 2005 17:32 GMT
It can be simpler than that. This will do the trick

Public Function Lastline() As Boolean
Lastline = ActiveDocument.Range.End = ActiveDocument.Bookmarks("\Line").End
End Function

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Hi
>
[quoted text clipped - 25 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 18 Jul 2005 17:53 GMT
Hi Jonathan,

I get an error:

"Function call of left-hand side of assignment
must return variant or object"

Hmm...

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Chuck Henrich - 18 Jul 2005 18:20 GMT
Hi Jonathan

Just to clarify:

Lastline = Activedocument.Range.End

will be true if the insertion point is at the end of the document while

Lastline = ActiveDocument.Bookmarks("\Line").End

will be true if the IP is at the end of the current line, yes?

Chuck

> It can be simpler than that. This will do the trick
>
[quoted text clipped - 31 lines]
> > Win XP, Office 2003
> > "red.sys" & Chr$(64) & "t-online.de"
Jonathan West - 18 Jul 2005 18:38 GMT
A correction

Public Function Lastline() As Boolean
Lastline = (ActiveDocument.Range.End -
ActiveDocument.Bookmarks("\Line").End) <= 1
End Function

This function returns true in the following circumstances

- The cursor is an insertion point, positioned somewhere on the last line of
the document, or
- The cursor is a solid selection whose start is somewhere on the last line
of the document.

The key to the function is that if the cursor is on the last line of the
document, the \Line built-in bookmark is marking the whole of the last line,
usually excluding the final paragraph mark. Therefore, you can compare its
End property with the end of the document itself to find out if the cursor
is on the last line.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> It can be simpler than that. This will do the trick
>
[quoted text clipped - 32 lines]
>> Win XP, Office 2003
>> "red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 19 Jul 2005 12:53 GMT
Hi Jonathan,

great. Live and learn.

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Dr. M - 18 Jul 2005 17:06 GMT
Thank you so much!
Signature

Dr. M

> This is a dumb question obviously [it's Monday] but how do I determine if my
> cursor is at the last line of the document, or end of file?
>
> Thank you so much.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.