Hello All,
I have a VBA program for producing Access Documentation which has a lot of statements like this:
I find this makes the code rather hard to read. I was thinking of replacing those lines with a call to the following subroutine:Code:With .ParagraphFormat.TabStops .ClearAll .Add Position:=oWordApp.InchesToPoints(2.25), _ Alignment:=0, Leader:=0 'wdAlignTabLeft wdTabLeaderSpaces .Add Position:=oWordApp.InchesToPoints(3.7), _ Alignment:=0, Leader:=0 'wdAlignTabLeft wdTabLeaderSpaces .Add Position:=oWordApp.InchesToPoints(5.5), _ Alignment:=2, Leader:=0 'wdAlignTabRight wdTabLeaderSpaces .Add Position:=oWordApp.InchesToPoints(6.4), _ Alignment:=2, Leader:=0 'wdAlignTabRight wdTabLeaderSpaces .Add Position:=oWordApp.InchesToPoints(7.4), _ Alignment:=2, Leader:=0 'wdAlignTabRight wdTabLeaderSpaces End With '.ParagraphFormat.TabStops
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?Code:Option Explicit Sub FMTDoc() 'Sample calling sequence SetTabStops Array(1.5, 0, 0, 3.5, 1, 0, 6.75, 2, 0) End Sub 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." Exit Sub End If 'With oWordApp.Selection.ParagraphFormat.Tabstops 'Word Object With ActiveDocument.Paragraphs.Format.TabStops 'In Word .ClearAll For iCntr = 0 To iLoop Step 3 .Add Position:=InchesToPoints(vTStops(iCntr)), _ Alignment:=vTStops(iCntr + 1), _ Leader:=vTStops(iCntr + 2) Next iCntr End With '.Format.Tabstops End Sub 'SetTabStops![]()



