PDA

View Full Version : Solved: GoToNext



mdmackillop
03-23-2007, 05:03 AM
The attachment is part of a large document which is being revised. For ease of data entry, I'm looking to add Bookmarrks/fields or other marker which will allow a GoNext type macro. What is the simplest/best way to accomplish this?
The document comprises tables in sections, in a proforma which cannot be substantially changed.

fumei
03-23-2007, 06:07 AM
Hi Malcolm. Could you explain your intention more?

How is this GoToNext fired?
Where does it start?
What is the relation to the Selection? That is, does it matter where the Selection may be?

Does the document require editing of existing text, or is it primarily data entry? If the latter, why not use formfields?

mdmackillop
03-23-2007, 06:44 AM
How is this GoToNext fired?
I'll assign a macro to a Function key
Where does it start?
From the beginning of the document, jumping to the first location for text to be entered.
What is the relation to the Selection? That is, does it matter where the Selection may be?
Text will be entered at the "empty" paragraph marks.
There should not be any editing. This is intended for audio typists doing data entry.

I may add meaningful bookmarks for navigation. I considered bookmarks for stepping to, but it seems I need to determine index numbers etc., which may not be the simplest method.

FYI, I did have this document set up a few years ago, when I used comments set with a hidden font (didn't know much VBA then) and a GoToNext comment. This worked fine, but that version is long gone, so I need to start again.

mdmackillop
03-23-2007, 11:45 AM
For bookmarks, I've come up with this
Sub GoToNextBM()

Dim Rng As Range, MyRng As Range

Set Rng = ActiveDocument.Range
Set MyRng = ActiveDocument.Range(Start:=0, End:=Selection.Range.End)

Rng.Bookmarks(MyRng.Bookmarks.Count + 1).Select

End Sub

fumei
03-23-2007, 12:11 PM
But wait a second here.

You say it is fired by shortcut key, and that it starts at the doc start.

OK. It jumps to the first marker. Now what? You are going to keep the code open and pass focus back to the document? Then...what? Wait for the user to type something...then get focus back to the code to goto next?

I am still not quite following the process.

mdmackillop
03-23-2007, 12:48 PM
Here's a sample. I've assigned the macro to F5, (but I don't know if it will travel.)
Next, I need the cursor to move on if nothing is typed in at a selection.

fumei
03-23-2007, 07:13 PM
The issue remains. Yes, the macro moves to the next bookmark. Now what? The code stops.
Next, I need the cursor to move on if nothing is typed in at a selection.How can you tell IF something is typed, or not.

The code has stopped.

Tell me again why are you not using formfields?

mdmackillop
03-26-2007, 06:02 AM
How can you tell IF something is typed, or not.
By inspection. Not required to be detected by the code. The typist should be able to press the shortcut again to move on to the next bookmark.


The code has stopped.Correct, going to the next bookmark is all I want it to do.


Tell me again why are you not using formfields?For my original purpose, I can set up the document useing formfields, but as it happens, I saw further applications for this where editing of boilerplate letter/report would be required, so stepping through bookmarks seemed like a more flexible solution.

fumei
03-26-2007, 06:09 AM
Oh, OK then. So the code is simply a goto next bookmark function. Then you have it. It does that.

The only issue I see is that if the bookmarks are, as in you r example, a single character locator, then it would be possible (likely) that eventually, the bookmark location movement would place the cursor before the location where the text is supposed to go. That is, unless the code backed up INTO the bookmark.

fumei
03-26-2007, 04:35 PM
What is actually very annoying about this whole thing is that while it looks like you can go simply use Selection.GotToNext to move to the next bookmark, and wdGotToBookmark IS listed as a What item....it does not work.

You have to do that dumb counting stuff that you did - the bookmark count + 1. Annoying.

mdmackillop
03-26-2007, 05:12 PM
You're right; it's very frustrating.

fumei
03-26-2007, 10:29 PM
And sorry, I do no think there is any way around it. Selection simply will not do a GoToNext wdGoToBookmark.

mdmackillop
03-27-2007, 03:35 AM
Finally figured it out (for my scenario anyway)
This will step through my bookmarks whether I type in text at a bookmark or not.


Sub GoToNextBM()

Dim Rng As Range, MyRng As Range

Set Rng = ActiveDocument.Range
Selection.MoveRight Unit:=wdCharacter, Count:=1
Set MyRng = ActiveDocument.Range(Start:=0, End:=Selection.Range.End)
Rng.Bookmarks(MyRng.Bookmarks.Count + 1).Select

End Sub

mdmackillop
03-29-2007, 11:48 AM
I tried to use this in a mailmerge situation. Of course the merged document does not contain the Bookmarks! :banghead:

fumei
03-30-2007, 02:37 AM
Poor Malcolm!!!!!!

The heading bashing is rather appropriate in this circumstance, isn't it?

Ah, but now you COULD use wdGoToField, as it IS a valid, and useable, property for Selection.GotToNext.

Keep slugging at it.