我先录制宏,然后想把它改成对段落格式处理的子程序。后来我发现,第一次执行正常。第二次执行就变成段前31.2镑了?什么原因,请各位大吓指教

解决方案 »

  1.   

    Private Sub setPformat(wordselect As Word.Selection, LeftIndent As Double, RightIndent As Double, firstlineblank As Integer, LineBefore As Integer, LineAfter As Integer, LineSpacingRule As Double, align As Integer)
    '段首空格CharacterUnitFirstLineIndent,段前段后距离LineUnitBefore = 2 LineUnitAfter = 2.5,行间间距  .LineSpacingRule = wdLineSpaceExactly, LineSpacing = 20/// LineSpacingRule = wdLineSpace1pt5, wdLineSpaceDouble
    'Alignment :wdAlignParagraphCenter对齐方式
    With wordselect.ParagraphFormat
            .LeftIndent = CentimetersToPoints(2)
            .RightIndent = CentimetersToPoints(0)
            .SpaceBefore = 6
            .SpaceBeforeAuto = False
            .SpaceAfter = 0
            .SpaceAfterAuto = False
     '       .LineSpacingRule = wdLineSpace1pt5
     Select Case LineSpacingRule
         Case 1.5
         .LineSpacingRule = wdLineSpace1pt5
         Case 2
         .LineSpacingRule = wdLineSpaceDouble
         Case 1
         .LineSpacingRule = wdLineSpaceSingle
    End Select
    Select Case align
    '        .Alignment = wdAlignParagraphJustify
    Case 0
    .Alignment = wdAlignParagraphLeft
    Case 1
    .Alignment = wdAlignParagraphCenter
    Case 2
    .Alignment = wdAlignParagraphRight
    End Select
     
            .WidowControl = False
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = CentimetersToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
           .CharacterUnitLeftIndent = LeftIndent  '左缩进
            .CharacterUnitRightIndent = RightIndent '右缩进
            .CharacterUnitFirstLineIndent = firstlineblank ' 首行空格数
            .LineUnitBefore = LineBefore  '段前行距
            .LineUnitAfter = LineAfter   '段后行距
            .AutoAdjustRightIndent = True
            .DisableLineHeightGrid = False
            .FarEastLineBreakControl = True
            .WordWrap = True
            .HangingPunctuation = False
            .HalfWidthPunctuationOnTopOfLine = False
            .AddSpaceBetweenFarEastAndAlpha = True
            .AddSpaceBetweenFarEastAndDigit = True
            .BaseLineAlignment = wdBaselineAlignAuto
        End With
    End Sub   Call setPformat(wordapp.Selection, 3, 0, 2, 0.5, 0, 1.5, 0)