-
May 27th, 2014, 04:45 PM
#1
Thread Starter
New Member
[RESOLVED] Stepping through each line in Word2007 VBA
I know Excel VBA quite well, and VB in general, but I'm working in Word and I'm not terribly famlliar with the Word Object model.
I can work within Word Tables quite well, provided the cursor is in one of the cells.
But what I'd like to be able to do is step through each line of a word document to get a table count. Or if there's a way to jump from table to table that would be just as good.
Can anyone point me to a quick code snippet that would get me started? I can build onto it after that.
Thanks.
Jeff
-
May 28th, 2014, 05:49 AM
#2
Re: Stepping through each line in Word2007 VBA
Code:
cnt = thisdocument.tables.count
change document object to suit
Code:
for each t in thisdocument.tables
msgbox t.cell(1, 1).range.text
'whatever
next
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 28th, 2014, 06:00 AM
#3
Thread Starter
New Member
[SOLVED][WORD]Re: Stepping through each line in Word2007 VBA
Originally Posted by westconn1
Code:
cnt = thisdocument.tables.count
change document object to suit
Code:
for each t in thisdocument.tables
msgbox t.cell(1, 1).range.text
'whatever
next
Ah, many thanks westconn1. That will be a great start for me. - Jeff
-
May 29th, 2014, 07:36 PM
#4
Thread Starter
New Member
Re: Stepping through each line in Word2007 VBA
Originally Posted by westconn1
Code:
cnt = thisdocument.tables.count
change document object to suit
Code:
for each t in thisdocument.tables
msgbox t.cell(1, 1).range.text
'whatever
next
Just thought I would say that I didn't get this to work as posted (probably my fault). But when I used ActiveDocument instead of thisdocument, it did.
thanks.
Jeff
-
May 30th, 2014, 04:18 AM
#5
Re: [RESOLVED] Stepping through each line in Word2007 VBA
note the line
change document object to suit
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 30th, 2014, 06:54 AM
#6
Thread Starter
New Member
Re: [RESOLVED] Stepping through each line in Word2007 VBA
Originally Posted by westconn1
note the line
change document object to suit
Yup, my bad. Thanks.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|