将光标定位在Word文档的开始/结束 [英] Position cursor at start/end of Word document

查看:252
本文介绍了将光标定位在Word文档的开始/结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在操纵我们的话从2007年的净使用Word互操作的文件。大多做的东西与领域中:

We are manipulating our Word 2007 documents from .Net using Word Interop. Mostly doing stuff with fields as in:

        For Each f In d.Fields
           f.Select()
           //do stuff with fields here            
        Next

这使得选择文档中的最后一个字段。

This leaves the last field in the document selected.

所以,为了整洁,我们想在文档的结束以定位光标(甚至在开始将是美好的)。

So, for the sake of neatness we would like to position the cursor at the end of the document (or even the start would be OK).

谷歌搜索的答案不扔了多少......最近我可以得到似乎在暗示我们需要对自己涉及与范围或书签。有一个转到方法Document对象,但没有一个WdGoToItem选项时,它提供了非常有用。

Googling for the answer doesn't throw up much ... the nearest I can get seems to be suggesting we need to involve ourselves with ranges or bookmarks. There's a GoTo method for the Document object but none of the WdGoToItem options it offers are useful.

还有就是不要只发送文件的光标移动到结束(或启动)一个简单的方法?

Isn't there a simple way to just send the cursor to the end (or start) of document?

修改

我的问题的一部分是我不喜欢留下选择的最后一个字段。现在已经意识到,我可以做

Part of my problem was I didn't like leaving the last field selected. Have now realised that I can do

f.Unlink

删除合并域和刚刚离开场还有文字为纯文本。这是整洁,我们是否不也重新定位光标

to remove the mergefield and just leave the field text there as plain text. Which is neater, whether or not we also reposition the cursor

推荐答案

@Alexander Kojevnikov:感谢您的帮助,因为你把我在正确的轨道。不过,我发现我已经到.GoTo应用到Word中选择的对象,而不是文件。如下所示:

@Alexander Kojevnikov: Thanks for your help because you put me on the right track. However I found I had to apply the .GoTo to the Word Selection object, not the Document. As in:

    Dim what As Object = Word.WdGoToItem.wdGoToLine
    Dim which As Object = Word.WdGoToDirection.wdGoToLast

    //below line had no effect
    //d.GoTo(what, which, Nothing, Nothing)

    w.Selection.GoTo(what, which, Nothing, Nothing)

这篇关于将光标定位在Word文档的开始/结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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