#1
|
|||
|
|||
Move cursor up several lines after form data entered in document
I have a Word template that is a letterhead. When the user opens a copy, a box comes up that asks them to fill out the files....Reference number, name and address of the recipient, subject, signature name and title....and enters all of the data in the letter at the appropriate bookmarks. This form works fine. However, what i would like to do is, after the last field is entered in the document, have the cursor jump up 7 lines to the main body of the letter....that is, between the Salutation and the signature lines. I had thought adding a subroutine like this would do it:
Public Sub MoveCursor() ' ' MoveCursor Macro ' ' Selection.MoveUp Unit:=wdLine, Count:=7 End Sub But either the routine is not correct, or I don't know how to properly call it after the form data is entered. Here is the coding for the form data that works fine, and note, i tried adding a line to call the MoveCursor subroutine: Private Sub cmdok_Click() If txtoperator.Text = "" Then MsgBox "You must enter in Our Reference Information!", vbInformation, "Enter Our Reference" Exit Sub End If If txtsubject.Text = "" Then MsgBox "You must enter in a Subject!", vbInformation, "Enter Subject" Exit Sub End If If txtsalutation.Text = "" Then MsgBox "You must enter something in the Salutation field!", vbInformation, "Enter Salutation" Exit Sub End If If txtsname.Text = "" Then MsgBox "You must enter the Sender's Name!", vbInformation, "Enter Sender's Name" Exit Sub End If If txtstitle.Text = "" Then MsgBox "You must enter the Sender's Title!", vbInformation, "Enter Sender's Title" Exit Sub End If Unload letterform Selection.Font.AllCaps = False Selection.Font.Italic = True Selection.Font.Bold = False Selection.GoTo What:=wdGoToBookmark, Name:="yourref" If Not txtYourRef = "" Then Selection.TypeText "Your Reference: " Selection.TypeText Text:=txtYourRef End If Selection.GoTo What:=wdGoToBookmark, Name:="ourref" Selection.TypeText "Our Reference: " Selection.TypeText Text:=txtoperator Selection.Font.Bold = False Selection.GoTo What:=wdGoToBookmark, Name:="DATE" Selection.TypeText Format(Date, "dd mmm yyyy") Selection.Paragraphs.TabStops.Add _ Position:=Application.CentimetersToPoints(2), _ Alignment:=wdAlignTabRight Selection.GoTo What:=wdGoToBookmark, Name:="name" Selection.TypeText Text:=txtname Selection.GoTo What:=wdGoToBookmark, Name:="address" Selection.TypeText Text:=txtaddress Selection.GoTo What:=wdGoToBookmark, Name:="addr2" Selection.Font.AllCaps = True Selection.TypeText Text:=txtaddr2 Selection.TypeParagraph With Selection.ParagraphFormat .LeftIndent = CentimetersToPoints(0) Selection.TypeParagraph Selection.TypeParagraph Selection.Font.AllCaps = False Selection.TypeText "Dear " Selection.TypeText Text:=txtsalutation Selection.TypeText "," Selection.TypeParagraph Selection.TypeParagraph If Not txtsubject = "" Then Selection.Font.Bold = True Selection.TypeText "Re: " Selection.TypeText Text:=txtsubject Selection.Font.Bold = False Selection.GoTo What:=wdGoToBookmark, Name:="sname" Selection.TypeText Text:=txtsname Selection.Font.Bold = True Selection.GoTo What:=wdGoToBookmark, Name:="stitle" Selection.TypeText Text:=txtstitle Selection.MoveUp Unit:=wdParagraph, Count:=8, Extend:=wdExtend Call MoveCursor End If End With Selection.EndKey Unit:=wdStory End Sub Am I asking the impossible, or can this be done? |
#2
|
||||
|
||||
The last line of your sub is moving the cursor to the end of the document so although you moved the cursor just before that, it sat there for only a millisecond before you asked it to move somewhere else.
Try deleting the Selection.endKey Unit:=wdStory line
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
better but not right yet
Quote:
Thank you. That is making progress. However, what it now does is to highlight the whole section from 7 lines up to the last entry. The top of the highlighted section is where I want the cursor to go, but not sure why it is highlighting that whole area. Zane |
#4
|
||||
|
||||
Why not simply bookmark the relevant location, then select that bookmark?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
||||
|
||||
You need to pay careful attention to your code. What do you expect that the Extend option does on the following line?
Selection.MoveUp Unit:=wdParagraph, Count:=8, Extend:=wdExtend Make that line end after the 8 and you will be moving the cursor instead of extending the selection
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
All Good!
Quote:
You can tell I am self taught. I get some of my lines of code from reading other people's and don't always understand what everything is for. Anyway, all good, thank you very much! |
#7
|
||||
|
||||
Ohh I can tell...
Whenever you can't work out what is happening, you can always step through the macro one line at a time and watch what is happening with each line. Press F8 to move through each line.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
form, moveup |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
A macro to find a symbol, delete it, and move the cursor to that location | JayBird24 | Word VBA | 1 | 08-19-2016 04:26 PM |
move cursor | anand | Word VBA | 14 | 07-07-2015 05:57 AM |
How do I move the cursor back to the text from a comment without using the mouse? | MsT | Word | 2 | 04-24-2014 05:48 PM |
Cursor skips to previous lines | KimM | Office | 1 | 01-09-2010 08:13 AM |
can't move the cursor in Word | pieboy | Word | 2 | 02-13-2009 07:15 PM |