Question

I have a combo box (combo1) in a word document and I would like to copy it to another word document. (end game will be looping through 100's of docs).

I can't for the life of me work out how to select and/or copy the combo box, although its easy enough to do outside of vba.

So far I've tried turning it into a bookmark, seems to select ok, but won't copy.

ActiveDocument.Bookmarks(combo1_bm).Select
Selection.Copy

I thought it would be able to done as an inline shape (as that is how they are added?), however again the selection appears to work, but the Copy doesn't.

ActiveDocument.InlineShapes(combo1).Select
Selection.Copy

Any ideas on what I can try next?

Cheers, Michael

Was it helpful?

Solution

Your attempt with bookmark was quite good. You just need to extend your code a bit:

ActiveDocument.Bookmarks("combo1_bm").Range.Copy
....
Selection.Paste        'or different pasting procedure

Keep in mind that you don't need to select object before copy it. Just try doing as I show above. Moreover, don't miss quotation marks for names or use bookmark index to work with appropriate one. Copy method will copy inside range of the bookmark and keep original bookmark in place, unchanged.

OTHER TIPS

This should do the trick.

Set ComboBox1Range = ActiveDocument.Range(Start:=ActiveDocument.Bookmarks("combo1_bm").Range.Start - 1, _
                             End:=ActiveDocument.Bookmarks("combo1_bm").Range.End)
ComboBox1Range.Expand Unit:=wdParagraph
ComboBox1Range.Copy
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top