有的时候,在使用VBA编写办公自动化功能的时候,单使用一行代码来写,可能会让单行的代码长度太长,不利于书写上的观察与修改。
  因此,在遇到这种问题的时候,常常需要将同一行的比较长的VBA代码进行换行,同时,还要保证,换行之后,多行的代码功能如同一行代码一样,在语法和功能上,不出任何问题。
  VBA代码的换行方法为:
  空格_回车
  下面我们以具体的示例来诠释换行是如何实现的。
  ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
  With ActiveWindow.Selection.TextRange
        .Text = "大众计算机学习网"
        With .Font
            .NameAscii = "Arial"
            .NameFarEast = "宋体"
            .NameOther = "Arial"
            .Size = 18
            .Bold = msoFalse
            .Italic = msoFalse
            .Underline = msoFalse
            .Shadow = msoFalse
            .Emboss = msoFalse
            .BaselineOffset = 0
            .AutoRotateNumbers = msoFalse
            .Color.SchemeColor = ppForeground
   End With
   End With
  比如,上面的这段代码,我们要对第一行进行换行,如何书写呢?可将第一行书写为如下:
  ActiveWindow.Selection.ShapeRange.TextFrame.TextRange _
    .Characters(Start:=1, Length:=0).Select   
  看到了吧,先在TextRange之后按下空格键,然后再输入_符号,最后再按下回车键,如此一来,
  .Characters(Start:=1, Length:=0).Select就变成另外一行了,但是,该行却与上一行属于同一行,在语法与功能上等同于单行。
  为方便您的学习,我们再看一段代码好了。
  未换行的代码段为:
  ActiveWindow.Selection.SlideRange.Shapes("Text Box 4").Select
  ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
  ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=8).Select
  With ActiveWindow.Selection.TextRange.Font
        .NameAscii = "华文细黑"
        .NameOther = "华文细黑"
        .NameFarEast = "宋体"
        .Size = 32
        .Bold = msoTrue
        .Italic = msoFalse
        .Underline = msoFalse
        .Shadow = msoFalse
        .Emboss = msoTrue
        .BaselineOffset = 0
        .AutoRotateNumbers = msoFalse
        .Color.SchemeColor = ppForeground
  End With
  换行之后的代码如下,我们仅对第三行换行,其它行不换。
  ActiveWindow.Selection.SlideRange.Shapes("Text Box 4").Select
  ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
  ActiveWindow.Selection.ShapeRange.TextFrame.TextRange. _
  Characters(Start:=1, Length:=8).Select
  With ActiveWindow.Selection.TextRange.Font
        .NameAscii = "华文细黑"
        .NameOther = "华文细黑"
        .NameFarEast = "宋体"
        .Size = 32
        .Bold = msoTrue
        .Italic = msoFalse
        .Underline = msoFalse
        .Shadow = msoFalse
        .Emboss = msoTrue
        .BaselineOffset = 0
        .AutoRotateNumbers = msoFalse
        .Color.SchemeColor = ppForeground
  End With