Hi Andreas,
Yes, the following appears to work fine, here:
Sub LoopThroughSelectedTables()
Dim nrList As String
Dim aIndexes() As Variant
Dim counter As Long
Dim nrTables As Long
nrList = InputBox("Enter the table indexes")
aIndexes() = ExtractNumbersFromString(nrList, ";", "-")
nrTables = ActiveDocument.Tables.Count
For counter = LBound(aIndexes()) To UBound(aIndexes())
If aIndexes(counter) <= nrTables Then
MsgBox "Table index: " & aIndexes(counter) & "." & vbCr & _
"Nr. rows: " & ActiveDocument.Tables(aIndexes
(counter)).Rows.Count
Else
MsgBox "There are only " & nrTables & " tables inthe
document." & vbCr & _
"You are trying to address table index " & aIndexes
(counter) & "!"
Exit For
End If
Next
End Sub
Function ExtractNumbersFromString(nrList As String, _
sepSingle As String, sepGroup As String) As Variant
Dim aNumbers() As Variant
Dim entry As String, startNr As String, endNr As String
Dim s As String
Dim posSingle As Long, posGroup As Long
Dim aCounter As Long, nrCounter As Long
s = nrList
aCounter = 0
Do
posSingle = InStr(s, sepSingle)
posGroup = InStr(s, sepGroup)
If (posSingle > 0 And posGroup > 0) _
And posSingle < posGroup Then
entry = Mid(s, 1, posSingle - 1)
If IsNumeric(entry) Then
ReDim Preserve aNumbers(aCounter)
aNumbers(aCounter) = entry
aCounter = aCounter + 1
End If
s = Mid(s, posSingle + 1)
ElseIf (posSingle > 0 And posGroup > 0) _
And posSingle > posGroup Then
startNr = Mid(s, 1, posGroup - 1)
endNr = Mid(s, posGroup + 1, (posSingle) - (posGroup + 1))
If IsNumeric(startNr) And IsNumeric(endNr) Then
For nrCounter = startNr To endNr
ReDim Preserve aNumbers(aCounter)
aNumbers(aCounter) = nrCounter
aCounter = aCounter + 1
Next
End If
s = Mid(s, posSingle + 1)
ElseIf posSingle > 0 Then
entry = Mid(s, 1, posSingle - 1)
If IsNumeric(entry) Then
ReDim Preserve aNumbers(aCounter)
aNumbers(aCounter) = entry
aCounter = aCounter + 1
End If
s = Mid(s, posSingle + 1)
ElseIf posGroup > 0 Then
startNr = Mid(s, 1, posGroup - 1)
endNr = Mid(s, posGroup + 1)
If IsNumeric(startNr) And IsNumeric(endNr) Then
For nrCounter = startNr To endNr
ReDim Preserve aNumbers(aCounter)
aNumbers(aCounter) = nrCounter
aCounter = aCounter + 1
Next
End If
s = Mid(s, posGroup + 1, Len(endNr))
Else
'What's left should be a number
entry = s
If IsNumeric(entry) Then
ReDim Preserve aNumbers(aCounter)
aNumbers(aCounter) = entry
aCounter = aCounter + 1
End If
s = ""
End If
Loop Until Len(s) = 0
ExtractNumbersFromString = aNumbers
End Function
Cindy Meister
INTER-Solutions, Switzerlandhttp://homepage.swissonline.ch/cindymeister(last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail