Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with macro to modify tabstops in Word 2003 documents 1

Status
Not open for further replies.

lfrandall

Technical User
Apr 11, 2008
6
US
Thank you for replying Skip. I'm sorry I posted this in the wrong forum. Here is what I'm doing. Lin

Code:
' This is designed to work with a manually selected block 
' of text. It is supposed to alter formatting of an 
' amendment received from Legal Svcs to fit half sized 
' paper (5.5x8.5). Basically, I need to halve all of the 
' formatting. LR


   Dim Para As Paragraph
   Dim g As Long
   Dim h As Long
   Dim i As Long
   Dim j As Long
   Dim k As Long
   Dim L As Integer
   Dim strCheck As String
   Dim myRange As Range
   Dim strMissed As String
   Dim rngPara As Range
   Dim TabLen(0) As PropertyAttributesEnum
   Dim myTab As TabStop

ActiveDocument.DefaultTabStop = InchesToPoints(0.25)

Set myRange = Selection.Range
   strMissed = ""
   Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
       
   For Each Para In myRange.Paragraphs
      Para.Range.Select
      Set rngPara = Selection.Range
         
     If Selection.Characters(1) = Chr(32) Then
        If Selection.Characters(2) = "(" Then
          Selection.Characters(1) = ""
        End If
      End If
      
        i = Para.LeftIndent
        If i > 0 Then
          j = i / 2
          Para.LeftIndent = j
        End If

        g = Para.FirstLineIndent
        If g > 0 Then
          j = g / 2
          Para.FirstLineIndent = j
        End If
        
'Here is where I need to halve all of the tabstops. I will 
'also need to reduce the font to 10.5pt but that shouldn't 
'be a problem.

   Next Para
End Sub
 



What does "'Here is where I need to halve all of the tabstops." mean?

Did you macro record changing any tabs?

Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 




Check out something like this...
Code:
        For Each myTab In Para.TabStops
            MsgBox myTab.Position
        Next
Maybe halving the position...
Code:
        For Each myTab In Para.TabStops
            with myTab
              .Position = .position/2
            end with
        Next
Also realize these values are in POINTS. You might need PointsToInches or InchesToPoints.

Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 
Hi lfrandall,

IMHO this approach to reformatting your document is all wrong!

What I think your organisation should do is to properly define and use the template Styles for both this document and the version being used by 'Legal Svcs'. That way, copying the text from the 'Legal Svcs' version of the document into a new or existing document based on your version of the template will automatically reformat the contents to fit the smaller format. The opposite also applies. You may still have to adjust any shapes & tables, but everything else will have been taken care of.

No macros needed!

Cheers

[MS MVP - Word]
 
Skip, I think the position/2 is going to help. I didn't think I could use that without inchestopoints, which required a value, and it wouldn't let me create an array of inchestopoints and assign it an integer value. The msgbox would probably work as well, but they don't have time for that generally as they are doing this in a crunch and usually in the middle of the night. I'll test it at work tomorrow. Thank you. Lin
 
Macropod,
Thank you for the tip. I guess I didn't explain it all very well. We do use templates. The amendments are based on the bill style as they become part of the bill which becomes statute and there is a whole book on how they have to be formatted. The amendment is also incorporated in other documents like minutes and this journal, which have totally different template styles and are secondary in importance to the bill. Thanks again. Lin
 
Hi Lin,

The fact that some styles may be used in one document and not the other doesn't detract from what I'm saying. If you set the Syles up correctly, according to the needs of each template, then there's no need to run a text reformatting macro when the text from one document is copied to the other. At most, you might need a macro to reformat tables and shapes.

Cheers

[MS MVP - Word]
 
I am completely with macropod on this. Text reformatting is in opposition to the use of Styles.

Just as a technical point, there is a misuse of Selection/Range. Or rather, a step that is not needed.
Code:
   For Each Para In myRange.Paragraphs
      Para.Range.Select
      Set rngPara = Selection.Range

Why Select...then make a Range object of the Selection? You can set the Range object directly. Your following code (that uses Selection to test characters) can just as easily be done on the Range object.
Code:
   For Each Para In myRange.Paragraphs
      Set rngPara = Para.Range

Done.

Also:
Code:
        i = Para.LeftIndent
        If i > 0 Then
          j = i / 2
          Para.LeftIndent = j
        End If

I am not sure why you bother with the variables. There is no real need for them.
Code:
  If Para.LeftIndent > 0 Then
     Para.LeftIndent = Para.LeftIndent / 2
  End If

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top