2011-08-11 111 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