View Full Version : Help with If Functions
VickyC
01-27-2006, 02:42 AM
Good Morning,
I am pretty new to this, so appologies.
I am wanting to create a macro in Word that will look up in the Active Document and if there is a second table appearing to convert the table to text.
And then go on to look for a 3rd table and do the same?
Can anybody help with commands, as mine does not seem to be working?
Many thanks, Vicky
Killian
01-27-2006, 03:13 AM
Hi Vicky and welcome to VBAX :hi:
You can do this by referring to each table by index - from 2 to the maximum numberDim i As Long
With ActiveDocument
If .Tables.Count > 1 Then
For i = 2 To .Tables.Count
.Tables(i).ConvertToText wdSeparateByCommas
Next i
End If
End WithHope that helps
VickyC
01-27-2006, 05:33 AM
Hi Killian,
Thank you for that it is great. Just tested it....... Many thanks,
VickyC
01-27-2006, 05:55 AM
Tony,
Thank you for that, much appreciated.
:yes
Killian
01-27-2006, 06:53 AM
Tony makes a very good point, as usual :thumb
Bottom up is indeed required for this situation :doh:
TonyJollans
01-27-2006, 06:58 AM
I haven't tested the code and it may well work (sometimes this kind of code does, mostly it doesn't), but a general word of warning here.
When you are deleting objects you should work from the bottom up. Consider what you are doing ..
Say you have 4 tables.
You convert table 2 to text. Now you have 3 tables.
You convert table 3 (which was table 4) to text.
Now you have 2 tables and your code is looking for table 4.
Oops (normally)
Instead, try using ..
With ActiveDocument
For i = .Tables.Count To 2 Step -1
.Tables(i).ConvertToText wdSeparateByCommas
Next i
End With
VickyC
01-27-2006, 07:05 AM
Thank you.
Sorry to be a pain, but do you also know how I can now extract this information and put the information into different cells in the first table?
Thanks,
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.