PDA

View Full Version : Keyword shortcut to End of Document



vpsekhar
09-30-2014, 08:39 AM
Hi All,
I had one word document of 200 pages. Currently my cursor is at beginning of 25 Th page. Now is there any keyboard short cut to move my cursor to end of the 25th page.

ranman256
09-30-2014, 12:58 PM
Selection.EndKey Unit:=wdStory

macropod
09-30-2014, 02:34 PM
Ranman: The OP asked for a keyboard shortcut. Your code is NOT a keyboard shortcut. Furthermore, the OP asked for something that, with the cursor at beginning of 25 Th page would move the cursor to end of the 25th page in a 200-page document. Your code does NOT do that, either.

vpeskhar: There is no single keyboard shortcut for this. However, Ctrl-PgDn, Left Arrow will get you there.

gmaxey
09-30-2014, 03:12 PM
You can create a macro to do it and then assign it to a simple keyboard shortcut:


Sub ScratchMacro()
With Selection
.Bookmarks("\page").Select
.Collapse wdCollapseEnd
If Not .Characters.Last = ActiveDocument.Range.Characters.Last Then
.MoveEnd wdCharacter, -1
End If
End With
End Sub

snb
10-01-2014, 08:32 AM
You can assign the macro M_snb to the key combination ctrl-Alt-spacebar with


Sub M_snb_000()
CustomizationContext = ThisDocument
KeyBindings.Add 1, "M_snb", BuildKeyCode(512, 1024, 32)
End Sub



Sub M_snb()
Selection.HomeKey 6
Application.Browser.Target = 1

For j = 1 To 24
Application.Browser.Next
Next
End Sub

vpsekhar
10-01-2014, 11:35 PM
You can create a macro to do it and then assign it to a simple keyboard shortcut:


Sub ScratchMacro()
With Selection
.Bookmarks("\page").Select
.Collapse wdCollapseEnd
If Not .Characters.Last = ActiveDocument.Range.Characters.Last Then
.MoveEnd wdCharacter, -1
End If
End With
End Sub

Hi
I run the macro ScratchMacro, after placing the cursor at begging of the page. After running this macro, the cursor is moved to next page , instead of moving to the end of the page. is it possible to move to end of page, instead of moving to next document.

macropod
10-02-2014, 12:16 AM
What's this about a 'next document'? What are you trying to achieve?

Greg's code moves the cursor to immediately before the last character on the page, not to the next page (or document). The problem with trying to move the cursor any further is that it would then move to the start of the next page.

vpsekhar
10-02-2014, 03:55 AM
What's this about a 'next document'? What are you trying to achieve?

Greg's code moves the cursor to immediately before the last character on the page, not to the next page (or document). The problem with trying to move the cursor any further is that it would then move to the start of the next page. word


Opened the 2nd page of 400 pages word document. Placed the cursor at the beginning of 2nd page and then i run the macro. When i again went back to word document cursor is placed at the 3rd page, but not at the end of 2nd page. Currently i am using the windows 2007 version, please check it in your local machine and let me know what is the result that you are getting.

gmayor
10-02-2014, 04:22 AM
Greg's macro performs exactly the same in all recent Word versions - including Word 2007.
Is your cursor in the text body when you run the macro?

vpsekhar
10-02-2014, 05:06 AM
Greg's macro performs exactly the same in all recent Word versions - including Word 2007.
Is your cursor in the text body when you run the macro?

Yes, before running this macro i placed my cursor at the text body of 2nd page. After running the macro cursor is located at 3 rd page. Please find the screen shots for the same.

macropod
10-02-2014, 05:11 AM
Currently i am using the windows 2007 version, please check it in your local machine and let me know what is the result that you are getting.
I did try it before posting. How else do you suppose I could confirm what it does? It even works the same in Word 2003 (yes, I've tested that version too).

Also, you haven't bothered to answer the question I asked. It seems this issue is related to whatever you're trying to do in your other thread but, until you're more forthcoming, there's little anyone can do to point you in the right direction.

gmaxey
10-02-2014, 10:44 AM
Try:


Sub ScratchMacroII()
Dim oRng As Word.Range
Selection.Bookmarks("\page").Select
Set oRng = Selection.Range
If Not oRng.End + 1 = ActiveDocument.Range.End Then
oRng.End = oRng.End - 1
End If
oRng.Collapse wdCollapseEnd
oRng.Select
End Sub

snb
10-02-2014, 01:16 PM
Perhaps


Sub M_snb()
With Application.Browser
.Target = 1
.Next
End With
Selection.MoveLeft 1, 1
End Sub

gmaxey
10-02-2014, 01:44 PM
snb,

It just isn't that easy. Your method falls over it the selection is in the last page of the document.

snb
10-03-2014, 03:23 PM
see #1


Hi All,
I had one word document of 200 pages. Currently my cursor is at beginning of 25 Th page. Now is there any keyboard short cut to move my cursor to end of the 25th page.

macropod
10-03-2014, 03:42 PM
snb: I'm appalled at how verbose your code is. Surely you can do better!

Sub Demo()
Application.Browser.Next: Selection.MoveLeft 1, 1
End Sub

gmaxey
10-03-2014, 04:10 PM
So your practice is to write code that works for page 25 of 200, or page 2 of 400, but falls over on page 200 of 200 or page 400 of 400? To each his own.

macropod
10-03-2014, 04:30 PM
Perhaps if one wants to be cryptic in the usual snb way but have code that actually works for any page:

Sub abc()
If Selection.Characters.Last.Information(3) < ActiveDocument.ComputeStatistics(2) Then
Application.Browser.Next: Selection.MoveLeft 1, 1
Else: Selection.EndKey 6: End If
End Sub

gmaxey
10-03-2014, 05:06 PM
Paul

I'm pretty sure you should explicitly set the target:

Sub abc()
If Selection.Characters.Last.Information(3) < ActiveDocument.ComputeStatistics(2) Then
Application.Browser.Target = 1: Application.Browser.Next: Selection.MoveLeft 1, 1
Else: Selection.EndKey 6: End If
End Sub