Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If possible, to write a Macro that will search for a prefix "SRS" in a WORD table and copy the prefix "SRS" with the number (SRS-1667) and the Section number with Name (1.1 Patient Search) in a table created at the end of the document?

The section in WORD
1.1 Patient Search
------------------------------------
-------------------------------| SRS1667 |
1.2 Patient Delete
------------------------------------
-------------------------------| SRS1668 |


The end results will look like this in a table

ID #	REQUIREMENTS	   TEST NAME
1.		     SRS-1667        Patient Search
2.		     SRS-1668        Patient Delete

What I have tried:

I do not know where to start. 123456789
Posted
Updated 28-Jun-21 20:31pm

You can use objects like
- Tables Interface (Microsoft.Office.Interop.Word) | Microsoft Docs[^]
- Rows.Item[Int32] Property (Microsoft.Office.Interop.Word) | Microsoft Docs[^]
- Cell Interface (Microsoft.Office.Interop.Word) | Microsoft Docs[^]
- and so on...

So something like
VB
Dim lastTable As Table
Dim row As row

Set lastTable = ActiveDocument.Tables(ActiveDocument.Tables.Count)

For Each row In lastTable.Rows
   If Left(row.Cells(2).Range.Text, 3) = "SRS" Then
      MsgBox "Found " & row.Cells(2).Range.Text
   End If
Next row
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900