开发者

VBA Word copy Table

Sorry in advance for my bad English and may be simple question. I want to copy Table object into Dictionary for place i开发者_高级运维t later in another Word document. All works are in Excel VBA. I try it for copy table:

Dim dict As Dictionary
Dim table1 As Word.table
Set table1 = Word.Application.ActiveDocument.Tables.Item(tableNum)                                            
dict.Add "SampleText","MyText"
dict.Add "tab1", table1

After it I close this document and open another. In it, I try to insert data from Dictionary to Bookmarks:

dim prilDoc As Word.Document
...
prilDoc.Bookmarks.Item("SampleText").Range.Text=dict.Item("SampleText")    

this (insert text) work fine, but I don't know, how to place Table object on Bookmark place, because I don't know VBA Word Object Model. I tryed some approaches, but can't find solution. I think there are two problems:

  1. When I put Table object into Dictionary, I in fact, copyed only reference to Table object in first Word document. And when I close this document and I try to get it from Dictionary object is deleted and I can't work with it. In Java I can deep cloning object, but I don't know how to do it in VBA. May be here must be use fully another approach.

  2. I don't know, how correctly must I insert Table object in new Word document.

Thanks in advance.


Did you try copying with the first document open? Don't close it before the contents are copied over.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜