Vba 消失文字

Vba 消失文字,vba,ms-word,Vba,Ms Word,我目前正在Word 2010中设置一些MS Word模板,遇到了一个问题,文本在段落末尾突然消失 这个问题只发生在一些特定的场景中,但我经历过,它可以通过许多不同的方式重新创建。然而,我还不能确切地指出发生这种情况的原因。因此,我想找出导致问题发生的具体原因,以避免它 似乎包装表的存在、页眉中的内容和某一行的长度的组合可以引发这个问题 若要重新创建出现此问题的文档,请按照以下步骤操作: 在Word 2010中打开新文档 将下面的代码复制到VBA编辑器中的新模块中 运行A_ReplicateSce

我目前正在Word 2010中设置一些MS Word模板,遇到了一个问题,文本在段落末尾突然消失

这个问题只发生在一些特定的场景中,但我经历过,它可以通过许多不同的方式重新创建。然而,我还不能确切地指出发生这种情况的原因。因此,我想找出导致问题发生的具体原因,以避免它

似乎包装表的存在、页眉中的内容和某一行的长度的组合可以引发这个问题

若要重新创建出现此问题的文档,请按照以下步骤操作:

  • 在Word 2010中打开新文档
  • 将下面的代码复制到VBA编辑器中的新模块中
  • 运行
    A_ReplicateScenario
    宏在文档中插入示例内容
  • 将光标放在第3行的末尾(靠近边距的那行)
  • 在点后键入一个新句子,以空格开头
  • 当达到页边空白时,您键入的文本将消失

    例如,如果从原始文本(即从行首)中删除了字符,或进行了格式更改(例如清除格式),则将显示文本。Word中的“全部显示”设置有时也可以显示文本,但仅在“全部显示”激活时显示。其他时候Word将显示无法选择的“重影”双线

    可在此处查看复制问题的简短视频:

    Sub A_ReplicateScenario()
    调用SetUpNormalStyle
    调用InsertBodyTextLines
    调用InsertHeaderTextLines
    调用InsertWrappedTables
    呼叫设置页边距
    调用InsertExampleBodyText
    端接头
    子设置NormalStyle()
    使用ActiveDocument.Styles(“普通”).Font
    .Name=“Arial”
    .尺寸=10
    以
    使用ActiveDocument.Styles(“正常”).ParagraphFormat
    .SpaceAfter=0
    .LineSpacingRule=wdlinespace至少
    .线间距=12
    以
    端接头
    子InsertBodyTextLines()
    对于i=1到4
    选择.类型段落
    下一个
    端接头
    子插入头文本行()
    如果ActiveWindow.View.SplitSpecial WDPaneOne,则
    活动窗口。窗格(2)。关闭
    如果结束
    如果ActiveWindow.ActivePane.View.Type=wdNormalView或ActiveWindow_
    ActivePane.View.Type=wdOutlineView然后
    ActiveWindow.ActivePane.View.Type=wdPrintView
    如果结束
    ActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeader
    对于i=1到26
    选择.类型段落
    下一个
    ActiveWindow.ActivePane.View.SeekView=WDSeekIndocument
    端接头
    子InsertWrappedTables()
    Selection.HomeKey单位:=wdStory
    ActiveDocument.Tables.Add范围:=Selection.Range,NumRows:=1,NumColumns:=1,DefaultTableBehavior:=wdWord9TableBehavior,AutoFitBehavior:=wdAutoFitFixed
    带Selection.Tables(1)行
    .wraproundText=True
    .水平位置=厘米点(2)
    .RelativeHorizontalPosition=WDRelativeHorizontalPosition页面
    .垂直位置=厘米S点(4.5)
    .RelativeVerticalPosition=wdRelativeVerticalPositionPage
    以
    Selection.Tables(1).Columns(1).PreferredWidthType=wdPreferredWidthPoints
    选择。表(1)。列(1)。首选宽度=厘米停止点(11)
    Selection.MoveDown单位:=wdLine,计数:=1
    ActiveDocument.Tables.Add范围:=Selection.Range,NumRows:=1,NumColumns:=1,DefaultTableBehavior:=wdWord9TableBehavior,AutoFitBehavior:=wdAutoFitFixed
    带Selection.Tables(1)行
    .wraproundText=True
    .水平位置=厘米S点(10)
    .RelativeHorizontalPosition=WDRelativeHorizontalPosition页面
    .垂直位置=厘米点(8)
    .RelativeVerticalPosition=wdRelativeVerticalPositionPage
    以
    Selection.Tables(1).Columns(1).PreferredWidthType=wdPreferredWidthPoints
    选择。表(1)。列(1)。首选宽度=厘米停止点(9)
    端接头
    子页边距()
    使用ActiveDocument.PageSetup
    .TopMargin=厘米停止点(3.8)
    .BottomMargin=厘米点(2.8)
    .LeftMargin=厘米停止点(2.3)
    .RightMargin=厘米点(1.5)
    以
    端接头
    子插入器示例BodyText()
    有选择
    .HomeKey单位:=wdStory
    .向下移动单位:=wdLine,计数:=3
    .TypeText Text:=“ouwouwoiwuwoiwuwoiwuwoiwuwoiwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwu
    .打字段落
    .TypeText:=“WOIUWOIUW。”
    以
    端接头
    
    问题与表格被格式化为围绕文本浮动有关。Word长期以来一直存在与浮动对象有关的问题。尽管Word在过去几年中有了很大的改进,但您可能仍然会遇到问题,特别是在浮动表方面

    如果更改第二个表的格式(通过表属性)并将文本换行设置为“无”,则错误会消失(YMMV)


    我的建议是尽可能避免浮动表

    我曾尝试在Word 2007和2013中测试相同的复制场景,但无法在此处触发问题。所以这似乎是Word 2010唯一的一期。这是我在这里看到的最好的复制步骤之一。伟大的在Word2013中,我也可以重新编程,但当我在安全模式下启动Word时,问题就消失了(只需在启动Word时按住Ctrl键)。不过,安全模式在Word 2010中似乎没有任何效果。这看起来确实像是Office中的一个bug,因此您可能对此无能为力。将表格移动到页眉或页脚有时也会有所帮助-尽管这并不总是一个选项,具体取决于文档内容等。感谢您的回复。这确实符合我在这个问题上的经验,浮动表有着重要的作用
    Sub A_ReplicateScenario()
    
        Call SetUpNormalStyle
        Call InsertBodyTextLines
        Call InsertHeaderTextLines
        Call InsertWrappedTables
        Call SetUpMargins
        Call InsertExampleBodyText
    
    End Sub
    
    Sub SetUpNormalStyle()
    
        With ActiveDocument.Styles("Normal").Font
            .Name = "Arial"
            .Size = 10
        End With
        With ActiveDocument.Styles("Normal").ParagraphFormat
            .SpaceAfter = 0
            .LineSpacingRule = wdLineSpaceAtLeast
            .LineSpacing = 12
        End With
    
    End Sub
    
    Sub InsertBodyTextLines()
    
        For i = 1 To 4
            Selection.TypeParagraph
        Next
    
    End Sub
    
    Sub InsertHeaderTextLines()
    
        If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
            ActiveWindow.Panes(2).Close
        End If
        If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
            ActivePane.View.Type = wdOutlineView Then
            ActiveWindow.ActivePane.View.Type = wdPrintView
        End If
    
        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    
        For i = 1 To 26
            Selection.TypeParagraph
        Next
    
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    
    End Sub
    
    Sub InsertWrappedTables()
    
        Selection.HomeKey Unit:=wdStory
    
        ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
        With Selection.Tables(1).Rows
            .WrapAroundText = True
            .HorizontalPosition = CentimetersToPoints(2)
            .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
            .VerticalPosition = CentimetersToPoints(4.5)
            .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        End With
        Selection.Tables(1).Columns(1).PreferredWidthType = wdPreferredWidthPoints
        Selection.Tables(1).Columns(1).PreferredWidth = CentimetersToPoints(11)
    
        Selection.MoveDown Unit:=wdLine, Count:=1
    
        ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
        With Selection.Tables(1).Rows
            .WrapAroundText = True
            .HorizontalPosition = CentimetersToPoints(10)
            .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
            .VerticalPosition = CentimetersToPoints(8)
            .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        End With
        Selection.Tables(1).Columns(1).PreferredWidthType = wdPreferredWidthPoints
        Selection.Tables(1).Columns(1).PreferredWidth = CentimetersToPoints(9)
    
    End Sub
    
    Sub SetUpMargins()
    
        With ActiveDocument.PageSetup
            .TopMargin = CentimetersToPoints(3.8)
            .BottomMargin = CentimetersToPoints(2.8)
            .LeftMargin = CentimetersToPoints(2.3)
            .RightMargin = CentimetersToPoints(1.5)
        End With
    
    End Sub
    
    Sub InsertExampleBodyText()
    
        With Selection
            .HomeKey Unit:=wdStory
            .MoveDown Unit:=wdLine, Count:=3
    
            .TypeText Text:="Ouwouwouwoiwoiuwoiuwoiuwoiuwoiuwoiuwoiw oiwu oiwu owiu woiu woiuw oiwu owiu owiu ww."
            .TypeParagraph
            .TypeText Text:="Woiuwoiuwoiuw."
        End With
    
    End Sub