2011-08-11 64 views
0

该webapp已在office2007上完成,我需要将其转换为Office2010中的工作。 我能够转换代码的头部生成器部分,但我有文档本身的问题。代码复制“data”文档中的数据并将其粘贴到生成的文档中。自动化word 2010来生成文档

appword.activewindow.activepane.view.seekview = 0 
    'set appsel1 = appword.activewindow.selection 
    set appsel1 = appword.window(filepath).selection  -that is the original one 
    appdoc1.bookmarks("b1").select 
    appword.selection.insertafter("some text") 
    appsel1.endkey(6)   -the code stops here 
    appword.selection.insertafter("some other text") 

iexplorer debuger说错误:需要appsel1对象。当我查看它的数据使用iexplorer调试器时,它的数据是“空”而不是“{...}”
任何人都可以告诉我我做错了什么
如果你需要更多的代码告诉我。

回答

0

MSDN

After this method is applied, the selection expands to include the new text.

If you use this method with a selection that refers to an entire paragraph, the text is inserted after the ending paragraph mark (the text will appear at the beginning of the next paragraph). To insert text at the end of a paragraph, determine the ending point and subtract 1 from this location (the paragraph mark is one character).

However, if the selection ends with a paragraph mark that also happens to be the end of the document, Microsoft Word inserts the text before the final paragraph mark rather than creating a new paragraph at the end of the document.

Also, if the selection is a bookmark, Word inserts the specified text but does not extend the selection or the bookmark to include the new text.

所以我怀疑你仍然没有选定的文本。

我不知道你是否可以做选择折叠(wdCollapseStart),但这只是一个想法。

+0

它应该选择它在word office 2007工作的文件中的所有文本 – Barakonda