• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

MS Word macro to pull customer IDs from table

Hi

I am trying to develope a bit of code. So the purpose of the code is to open up word templates, find all of the alternative customer IDs for a given customer and return the values into Excel.

The problem I have is not knowing how to make VBA recognise the end of a table. My word vba skills are not good, and I have been teaching myself the past few days.

Here is the code that finds the customer IDs, and returns all of the IDs available.

With WApp.Selection
.HomeKey unit:=6
.Find.ClearFormatting
.Find.Execute "Customer ID"
.MoveRight unit:=2, Count:=2
.MoveRight unit:=wdCell, Count:=wdWord, Extend:=wdMove
.MoveRight unit:=2, Count:=2
.MoveRight unit:=wdCell, Count:=wdWord, Extend:=wdMove
.MoveRight unit:=2, Count:=2
.MoveRight unit:=wdCell, Count:=wdWord, Extend:=wdMove
End With

This moves down through each cell in the table and tries to capture all of the possible IDs. However, the number of different IDs to capture can be anywhere between 1 and 10 (the upper bound number is not certain), and I do not know how to tell VBA to find all of the possible IDs, without repeating:

.MoveRight unit:=2, Count:=2
.MoveRight unit:=wdCell, Count:=wdWord, Extend:=wdMove

Does anyone know how I would tell vba to go through each vertical cell in the word table, UNTIL the end of the table?

Thanks

EJ
 
Back
Top