Solved

Easy Word/Visual Basic Question "Selections"

Posted on 2000-03-09
13
186 Views
Last Modified: 2013-11-25
Hey, I can't quite figure something out.  Keep in mind I'm not using real VB, I'm using Word VB.

I can place things in my document and I can have different things select and such, but is there a way I can have the cursor go to the last line of a specificed page?  I was hoping there was a command like:

"Activedocument.MoveEndOfPage"

There isn't one, unfortunately.  Any equivelant to do such?

Thanks for any help..

0
Comment
Question by:saksafon2
  • 6
  • 6
13 Comments
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2602330
Have you looked at the Goto method of the Selection object?  It looks like this syntax might work after you select the page/document/whatever:

Selection.Goto Which:=wdGoToLast

Wes
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2602339
This is from Word Help regarding the .End property:

This example retrieves the ending position of the selection. This value is used to create a range so that a field can be inserted after the selection.

pos = Selection.End
Set myRange = ActiveDocument.Range(Start:=pos, End:=pos)
ActiveDocument.Fields.Add Range:=myRange, Type:=wdFieldAuthor

Wes
0
 
LVL 1

Expert Comment

by:paul_tsekov
ID: 2602409
Hi VBfan,
 if there is a thing like ActiveDocument.SetFocus

then you could use the three following rows:

  ActiveDocument.SetFocus
  SendKeys "{PGDN}"
  SendKeys "{Home}"

ghgfgh
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 4

Expert Comment

by:wesleystewart
ID: 2602456
That would certainly work, but I would avoid SendKeys like the plague.  If that's the only way you can do it that's fine, but otherwise . . .

Wes
0
 

Author Comment

by:saksafon2
ID: 2604331
I'm working with not-very intelligent people.
Sending something flimsy like a sendkey might cause problems down the road.

Thanks for the response, though!

rick
0
 

Author Comment

by:saksafon2
ID: 2604359
^^ About my comment, don't take that the wrong way, I just read my comment over and laughed.  I meant it as the people I'm working with on my job.  Someone might mess with the document and throw things off.. lol

rick
0
 

Author Comment

by:saksafon2
ID: 2604382
Adjusted points to 30
0
 

Author Comment

by:saksafon2
ID: 2604383

Wes, I see what your saying about the Goto end..
How can I go about selecting the entire page (including <CR>'s) so that this will work?

rick


0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2604421
Did you try:

ActiveDocument.Select
Selection.Goto Which:=wdGoToLast

That might be a little cludgy.  I'll see if I can find something else.

Wes
0
 

Author Comment

by:saksafon2
ID: 2604829
Thats the right track, except

"ActiveDocument.Select"...

selects the entire 4 page document.  I'd like it to suggest just the first page.. Hmmm..

I'm figuring it would be similar to "ActiveDocument.Paragraphs(1).Range.Select"

Like.. "ActiveDocument.Page(1).Range.Select", but page isn't an ob.

Hm!

rick
0
 
LVL 4

Accepted Solution

by:
wesleystewart earned 50 total points
ID: 2604895
Here's another useful widget:

Selection.InsertAfter "End of section 1."

It looks like the InsertAfter takes you to teh end of the selection also.

Alas, I couldn't find any Pages property.  It looks like paragraphs will have to do.

You can access Sections of the document with:

Document.Sections(1)

if you have split your document into sections, which you can do with >>Insert>>Break

Wes
0
 

Author Comment

by:saksafon2
ID: 2605100
Wonderful!  Your comment about adding the Sections did it.  Here is the outcome:

What I needed to do was place a signature line and a few other lines of text at the end of the page.  It tried just having a bookmark to go to, but when I'd have my variable body text added, it would push the bookmark down and make it impossible to line up.  Now, the end of page 1 is a section break.

ActiveDocument.Sections(1).Range.Select
Selection.GoTo.EndOf (wdSection)
Selection.MoveUp unit:=wdLine, Count:=10

I select the first section (which is page one), go to the end of the section which kicks the cursor to the opening of page two, and bring it up ten lines to place the information where I needed it.

Thanks for your help!  I appreciate your efforts.

-Rick Detroit
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2605118
Happy to help.  

Good Luck in the future.  Word seems to have the most convoluted object model of all the Office products . . .

Wes
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 63
how to know if my Checkbox is True in VB6.0? 9 54
Authentication of Web Services 3 72
RUNRMTCMD from AS/400 12 44
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question