![]() |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
Hello,
I am trying to create an application, which verifies if an in-text table (or figure, equation) reference was created using Microsoft Word's "cross reference" feature. For example, in a Word document, if there was a sentence that stated, "Please see Table 1 for further details," I want the application to verify that the author used Word's insert cross-reference feature and didn't just simply type "Table 1." Basically, is there a field code associated with "Table 1?" Finding all of the "Table" occurrences is easy enough. However, I cannot figure out how to determine if they are associated with a table using Word's cross-reference feature. I have started my code in Excel, because I eventually want to create a spreadsheet of all of the occurrences, once I figure out the other part. Here is my code so far. Any help would be appreciated! Thanks, Roy Code:
Sub findRef() ' Dim wdApp As Object Dim wdDoc As Object Dim aRng As Object Dim strFile As String With Application.FileDialog(msoFileDialogOpen) If .Show = -1 Then strFile = .SelectedItems(1) End If End With If strFile = "" Then Exit Sub End If On Error Resume Next Set wdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then Set wdApp = CreateObject("Word.Application") wdApp.Visible = False End If Set wdDoc = wdApp.Documents.Open(Filename:=strFile, AddToRecentFiles:=False, Visible:=False) Set aRng = wdDoc.Range With aRng.Find .ClearFormatting .Text = "Table?[0-9]" .MatchWildcards = True Do While .Execute ' Loop until Word can no longer find the search string 'if aRng.text = cross reference field code ... Loop End With wdDoc.Close False Set aRng = Nothing Set wdDoc = Nothing wdApp.Quit Set wdApp = Nothing End Sub Last edited by scienceguy; 10-23-2021 at 07:09 AM. |
Tags |
microsoft word |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
mgdawn672017 | Word | 3 | 09-17-2018 03:05 PM |
![]() |
Toto | Word | 1 | 06-07-2014 03:51 PM |
cross reference hyperlinks to text box | nothing_kills | Word | 4 | 11-25-2013 09:21 AM |
![]() |
wmac | Word | 1 | 05-14-2013 08:54 PM |
Cross-reference feature problems in Word 2010 | bannisa | Word | 0 | 02-13-2011 03:28 AM |