I find this makes the code rather hard to read. I was thinking of replacing those lines with a call to the following subroutine:
'Sample calling sequence
SetTabStops Array(1.5, 0, 0, 3.5, 1, 0, 6.75, 2, 0)
Sub SetTabStops(vTStops As Variant)
Dim iCntr As Integer
Dim iLoop As Integer
Dim iExtra As Integer
Dim zWds(1 To 2, 1 To 2)
zWds(1, 1) = "was "
zWds(1, 2) = "argument."
zWds(2, 1) = "were "
zWds(2, 2) = "arguments."
iLoop = UBound(vTStops)
iExtra = (iLoop + 1) Mod 3
If iExtra <> 0 Then
MsgBox "Passed array requires arguments in sets of 3" & vbCrLf & _
"1 - Tab Position" & vbCrLf & _
"2 - Tab Alignment" & vbCrLf & _
"3 - Tab Leader" & vbCrLf & vbCrLf & _
"There " & zWds(iExtra, 1) & Format(iExtra) & _
" extra " & zWds(iExtra, 2) & vbCrLf & vbCrLf & _
"Please Correct your calling statement.", _
vbCritical & vbOKOnly, _
"Error: Incorrect number of arguments."
'With oWordApp.Selection.ParagraphFormat.Tabstops 'Word Object
With ActiveDocument.Paragraphs.Format.TabStops 'In Word
For iCntr = 0 To iLoop Step 3
.Add Position:=InchesToPoints(vTStops(iCntr)), _
Alignment:=vTStops(iCntr + 1), _
Leader:=vTStops(iCntr + 2)
End With '.Format.Tabstops
End Sub 'SetTabStops
I'm sure making a bunch of calls is inefficient but I think the increase in readability of the code makes up for it. The subroutine will be called at max of about 50 times depending on selections made by the user at run time. So what do y'all think?
Subscribe to get a FREE chapter from Windows 7 The Missing Manual
This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
I'm not sure I agree that the original code is any less readable and it could be made more so by declaring 'wdAlignTabLeft' and 'wdTabLeaderSpaces' as constants (with their corresponding values) so that you could continue to use 'wdAlignTabLeft' and 'wdTabLeaderSpaces' in the code. This also facilitiates the transition between early & late binding.
Const wdAlignTabLeft As Long = 0, wdAlignTabCenter = 1, wdAlignTabRight = 2
Const wdAlignTabDecimal = 3, wdAlignTabBar = 4, wdAlignTabList = 6
Const wdTabLeaderSpaces As Long = 0, wdTabLeaderDots = 1, wdTabLeaderDashes = 2
Const wdTabLeaderLines = 3, wdTabLeaderHeavy = 4, wdTabLeaderMiddleDot = 5
.Add Position:=oWordApp.InchesToPoints(2.25), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Add Position:=oWordApp.InchesToPoints(3.7), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Add Position:=oWordApp.InchesToPoints(5.5), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Add Position:=oWordApp.InchesToPoints(6.4), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Add Position:=oWordApp.InchesToPoints(7.4), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces