Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-22-2018, 09:33 PM
zanestein zanestein is offline Move cursor up several lines after form data entered in document Windows 7 32bit Move cursor up several lines after form data entered in document Office 2010 32bit
Novice
Move cursor up several lines after form data entered in document
 
Join Date: May 2018
Posts: 4
zanestein is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 05-23-2018, 01:27 AM
Guessed's Avatar
Guessed Guessed is offline Move cursor up several lines after form data entered in document Windows 10 Move cursor up several lines after form data entered in document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 05-23-2018, 01:43 AM
zanestein zanestein is offline Move cursor up several lines after form data entered in document Windows 7 32bit Move cursor up several lines after form data entered in document Office 2010 32bit
Novice
Move cursor up several lines after form data entered in document
 
Join Date: May 2018
Posts: 4
zanestein is on a distinguished road
Default better but not right yet

Quote:
Originally Posted by Guessed View Post
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

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
Attached Images
File Type: jpg test.JPG (11.6 KB, 13 views)
Reply With Quote
  #4  
Old 05-23-2018, 02:55 AM
macropod's Avatar
macropod macropod is offline Move cursor up several lines after form data entered in document Windows 7 64bit Move cursor up several lines after form data entered in document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Why not simply bookmark the relevant location, then select that bookmark?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-23-2018, 03:03 AM
Guessed's Avatar
Guessed Guessed is offline Move cursor up several lines after form data entered in document Windows 10 Move cursor up several lines after form data entered in document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #6  
Old 05-23-2018, 03:26 AM
zanestein zanestein is offline Move cursor up several lines after form data entered in document Windows 7 32bit Move cursor up several lines after form data entered in document Office 2010 32bit
Novice
Move cursor up several lines after form data entered in document
 
Join Date: May 2018
Posts: 4
zanestein is on a distinguished road
Smile All Good!

Quote:
Originally Posted by Guessed View Post
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
Thank you! That did it.
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!
Reply With Quote
  #7  
Old 05-23-2018, 04:01 AM
Guessed's Avatar
Guessed Guessed is offline Move cursor up several lines after form data entered in document Windows 10 Move cursor up several lines after form data entered in document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
Reply

Tags
form, moveup

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move cursor up several lines after form data entered in document 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 up several lines after form data entered in document 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:17 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft