#1
|
|||
|
|||
Find Bookmark, move to bookmark, execute code, repeat
Newbie question.
Code is: Sub EnterTranscriptPages() While ActiveDocument.Bookmarks.Exists("TranscriptPage") = True Selection.Find.Execute Selection.NextField.Select Selection.Fields.Update Wend End Sub Problem is I need to see the field so I can read the paragraphs around the field so I can know what info to enter into the update box. Now it runs the code, shows me each input box, but doesn't change the screen from the starting point. |
#2
|
||||
|
||||
What EXACTLY is it that you think this code is trying to achieve?
What sort of 'fields' are involved. If you want to call bookmarks and go to them then call them by name. If you want to move between fields F11 is pre configured to do that. If you want to change the contents of a bookmark then see the FillBM function you can find on my web site.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thank you for attending to my question.
I want the code to move me to each instance of the bookmark "TranscriptPage" Open a box asking for the page reference allow me to look up the page reference for the quote, then enter the page reference into the box then move to the next instance of the bookmark "TranscriptPage" and repeat until no further instance of the bookmark The fields are "ASK" fields. The code does call the bookmarks by name, the name of each bookmark where page numbers are required is "TranscriptPage". There are multiple instances of bookmarks names "TranscriptPage". Yes, F11 will move me to the bookmark, but F11 won't open the ASK box and let me enter the page number, then insert the page number into the document, then repeat with next spot. I don't want to change the contents of the bookmark. The bookmark is where a page reference is needed. The ASK field gathers the page number and enters it into the document. I hope that explains what I'm trying to do. |
#4
|
|||
|
|||
Attachment
See attachment
|
#5
|
|||
|
|||
Try this:
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oFld As Field Dim oRng As Range For Each oFld In ActiveDocument.Range.Fields If oFld.Type = wdFieldAsk Then If InStr(oFld.Code, "TranscriptPage") > 0 Then Set oRng = oFld.Code oRng.Collapse wdCollapseStart oRng.Select oFld.Update End If End If Next lbl_Exit: Exit Sub End Sub |
#6
|
|||
|
|||
That works, thank you so very much, you have solved a problem for me and given me a macro to study for further use. Well done.
I did notice that the page number at the bottom doesn't update, it stays the same throughout. Is there an easy fix for this? |
#7
|
|||
|
|||
Try adding ActiveDocument.Fields.Update at before the lbl_Exit line.
|
#8
|
|||
|
|||
Thank you for your suggestion.
I copied ActiveDocument.Fields.Update and put it before the lbl_Exit line so the code was: Dim oFld As Field Dim oRng As Range For Each oFld In ActiveDocument.Range.Fields If oFld.Type = wdFieldAsk Then If InStr(oFld.Code, "TranscriptPage") > 0 Then Set oRng = oFld.Code oRng.Collapse wdCollapseStart oRng.Select oFld.Update End If End If Next ActiveDocument.Fields.Update lbl_Exit: Exit Sub End Sub The bar at the bottom of the page still did not update to show the current page name. Also the current document contains 7 instances of "TranscriptPage". The macro goes through the document once allowing me to enter the pages numbers, then the macro repeats showing the ASK box again, starting at the beginning, showing each sequentially to the last one. |
#9
|
|||
|
|||
Yeah, that was a bad idea. That is causing all the Ask fields to update again. What "bar" at the bottom of the page are you talking about?
|
#10
|
|||
|
|||
See attachment.
I think it is called the Status Bar. |
#11
|
|||
|
|||
Well here the status bar updates to reflect whatever page number has the selection.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Iterating through tables to find a bookmark | bgmsd | Word VBA | 12 | 06-08-2015 10:09 AM |
Bookmark Not Showing Bookmark | RegAudit | Word | 6 | 03-16-2015 11:08 PM |
Move shape to bookmark location | Byron Polk | Word VBA | 4 | 08-07-2014 03:21 AM |
vba to go to next bookmark | megatronixs | Word VBA | 2 | 06-08-2014 09:53 PM |
Find and Execute | cksm4 | Word VBA | 1 | 10-22-2011 11:36 PM |