2017-09-29 145 views
0

我试图在VBA for Word中的两个内容控件之间获取行。 我想在两个内容控件之间设置默认换行符。 如果它是两个以上的换行符,我想删除其他。VBA - 在两个内容控件之间设置默认换行码

在循环中执行我的代码时,将字符串合并到内容控件中会使合并到内容控件中时出现多行换行。

如何在两个内容控件之间设置默认的两个换行符?

Content control A 
- line break 
- line break 
Content control B 
+0

如果您需要关于代码的帮助,如果您在问题中包含它,它会有很大的帮助。 – braX

+0

我找到了解决方案。子RemoveLineBreak() 昏暗RSTART作为范围 昏暗雷德作为范围 ActiveDocument.SelectContentControlsByTag( “ContentC1”)项目(1).Range.Select Selection.MoveDown单位:= wdLine,计数:= 1 设置RSTART = Selection.Range ActiveDocument.SelectContentControlsByTag( “ContentC2”)项目(1).Range.Select Selection.MoveUp单位:= wdLine,计数:= 1 集雷德= Selection.Range 的ActiveDocument。范围(rStart.Start,rEnd.End)。选择 Selection.Delete Selection.InsertBreak类型:= wdLineBreak End Sub – CaptainYankee

回答

0

我找到了解决办法。

Sub RemoveLineBreak() 

Dim rStart As Range 
Dim rEnd As Range 


    ActiveDocument.SelectContentControlsByTag("ContentC1").Item(1).Range.Select 
    Selection.MoveDown Unit:=wdLine, Count:=1 

Set rStart = Selection.Range 

    ActiveDocument.SelectContentControlsByTag("ContentC2").Item(1).Range.Select 
    Selection.MoveUp Unit:=wdLine, Count:=1 

Set rEnd = Selection.Range 

    ActiveDocument.Range(rStart.Start, rEnd.End).Select 
    Selection.Delete 
    Selection.InsertBreak Type:=wdLineBreak 

End Sub