Word.Range.TextVisibleOnScreen? [英] Word.Range.TextVisibleOnScreen?

查看:87
本文介绍了Word.Range.TextVisibleOnScreen?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Word.Range.TextVisibleOnScreen属性实际起作用吗?

Does the Word.Range.TextVisibleOnScreen property actually work?

Private Sub isVisTest()
  Dim rng As Range: Set rng = oDoc.Bookmarks("_Toc#########").Range
  'replace ######### with a good Heading bookmark number from your test document
  Dim c As Integer

  ActiveWindow.VerticalPercentScrolled = 0
  ActiveWindow.HorizontalPercentScrolled = 0
  oDoc.ActiveWindow.ScrollIntoView rng
  Do
    oDoc.ActiveWindow.SmallScroll Down:=6
Debug.Print rng.TextVisibleOnScreen
    c = c + 1
    If c > 10 Then Exit Do
  Loop Until rng.TextVisibleOnScreen = 0
  oDoc.ActiveWindow.SmallScroll Up:=6
End Sub

缩写过程使用标题"书签在屏幕顶部显示相应的标题.simto Word的内置导航窗格行为. Do-Loop是将Heading移至页面顶部的一种改进,但是我发现rng.TextVisibleOnScreen属性永远不会更改,而不管rng对象是否在屏幕上实际可见;总是-1.因此,该属性似乎被禁用.但是, MSDN 不会不会将其报告为已禁用或已弃用.

The abbreviated procedure uses Heading bookmark to display the corresponding Heading at the top of the screen simto Word's built-in Nav Pane behavior. The Do-Loop is a refinement to bring the Heading to top of page but I'm finding that the rng.TextVisibleOnScreen property never changes regardless of whether the rng object is actually visible onscreen or not; it's always -1. Thus the property seems disabled. However, MSDN doesn't report it as being disabled or deprecated.

可以使用选择"和IDE的即时"窗口(即?Selection.Range.TextVisibleOnScreen)来完成相同的测试.我得到相同的结果;始终为-1.

The same test can be done by using a Selection and the IDE's Immediate window, i.e., ?Selection.Range.TextVisibleOnScreen. I get the same result; always -1.

推荐答案

如果该范围内的所有文本都为,则TextVisibleOnScreen属性返回1 可见的;如果看不到该范围内的任何文本,则返回0;否则返回0.和它 如果可见范围内的某些文本,而看不到该范围的文本,则返回-1.文本 不可见的内容可能是例如折叠的文本 标题.

The TextVisibleOnScreen property returns 1 if all text in the range is visible; it returns 0 if no text in the range is visible; and it returns -1 if some text in the range is visible and some is not. Text that is not visible could be, for example, text that is in a collapsed heading.

此属性使您知道Range是否由于折叠或展开标题样式而可见.同时在Word 2013中引入了折叠/展开标题下的文本部分的功能.

this property lets you know whether a Range is visible or not due to a Heading style being collapsed or expanded. The capability to collapse/expand sections of text under a heading was introduced at the same time - in Word 2013.

是隐藏文本还是将其滚动到屏幕外都无关.

It has nothing to do whether text is hidden or scrolled off the screen.

绝对奇怪/误导性的陈述是,当可见的东西返回1,而当部分可见的时候返回-1.我认为这是文档中的错误,可能是2013年Beta版中从未纠正过的错误.

What is definitely odd / misleading is the statement that 1 is returned when something is visible and -1 when something is only partially visible. I believe this is a mistake in the documentation, possibly from the 2013 beta that never was corrected.

由于范围(折叠前的标题样式)不可见,因此以下代码返回0(该范围在文档中的第二段):

The following code returns 0 when the range (second paragraph in the document) is not visible because a heading style before it is collapsed:

Sub TestHiddenText
  Dim rng as Word.Range

  Set rng = ActiveDocument.Paragraphs(3).Range
  Debug.Print rng.TextVisibleOnScreen
End Sub

展开标题时,上面的代码返回-1(传统上在Word中始终为"true".)

When the heading is expanded, the above returns -1 (which traditionally has always been "true" in Word).

如果我折叠该标题,但测试了整个文档,则混合状态将返回我希望从Word中获得的状态-未定义:9999999

If I collapse that heading, but test the entire document, the mixed status returns what I'd expect from Word - undefined: 9999999

Sub TestHiddenText
  Dim rng as Word.Range

  Set rng = ActiveDocument.Content
  Debug.Print rng.TextVisibleOnScreen
End Sub  

这篇关于Word.Range.TextVisibleOnScreen?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆