#1
|
|||
|
|||
selecting ms word bookmarks using vba
I'm using for each loops to search thru some word tables to find enclosing bookmarks. There are several rows and several cells per row. Several cells have enclosing bookmarks, in the cell. As I loop thru the cells in a row I use a for each loop to look for bookmarks in the cell. I would expect each cell to "see" only it's bookmarks but all of the bookmarks in the row are selected one after the other. So if there are six cells in a row and only two cells have one bookmark each, I see each bookmark selected six times not once as I would expect.
Code:
For Each wRow In wTbl.Rows For Each wCell In wRow.Cells wCell.Select wApp.Selection.Range.Collapse wdCollapseStart For Each wBmk In wApp.Selection.Bookmarks wBmk.Range.HighlightColorIndex = wdBlue Sleep 150 wBmk.Range.HighlightColorIndex = wdNoHighlight Sleep 150 Next Next Next Last edited by macropod; 05-10-2013 at 04:02 PM. Reason: Added code tags & formatting |
#2
|
|||
|
|||
Well if all you want to do is action the bookmarks, then just action the bookmarks. There is no need to select anything.
Code:
Sub HighlightBM_InTable() Dim BM As Bookmark For Each BM In Selection.Tables(1).Range.Bookmarks BM.Range.HighlightColorIndex = wdBlue Next End Sub Code:
Sub HighlightBM_InTable() Dim BM As Bookmark Dim oTable As Table For Each oTable in ActiveDocument.Tables() For Each BM In oTable.Range.Bookmarks BM.Range.HighlightColorIndex = wdBlue Next Next End Sub |
#3
|
|||
|
|||
The highlighting is just for testing. I'm actually collecting the page position of the bookmark and the cell widths and heights. This is then used to OCR just those areas after the forms are filled out and scanned in. I have been collecting this bookmark info already but it is slow. Right now I just delete the access record and let VBA update the new record six times. If there is no solution I will just continue on, and maybe look for a solution at a later time. As a note the Word documents (field forms) are created/revised/update every few months, this is when the word documents are processed for the bookmark positions. Usually the forms are printed with their info pulled in from an Access database. They then go to the field and are filled in, signed and dated, returned to the office where they scanned and OCR'ed.
|
#4
|
||||
|
||||
Quote:
Even so, what fumei says is relevant - you can interrogate the bookmarks directly (without selecting them) to get all you need to know about where they are, including where their cells are on the page and the cell dimensions, and all without ever looking at anything else in the document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I understood what you said the first time about testing. I used your example.
Quote:
I have to agree with macropod about OCR. It seems truly strange. If the point is to get data from them, you can do so directly. Last edited by fumei; 05-10-2013 at 07:35 PM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word vs bookmarks, another instance <g> | eNGiNe | Word | 6 | 12-05-2012 01:05 AM |
VBA equivalent to selecting present word | KevinJ | Word VBA | 2 | 11-05-2012 01:27 PM |
Autocorrect in Word not selecting proper entry from list | Llewella | Word | 4 | 05-12-2012 02:22 PM |
Word 2007 bookmarks and protection | Stevejd58 | Word | 0 | 07-31-2011 11:53 AM |
word 2007 bookmarks | Dawn | Word | 0 | 07-14-2009 01:00 PM |